Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 8, 1997



Application Security Testing: An Integral Part of DevOps

Simplifying the Condition-Part of an If statement

When you write an If statement such as:

If Category = "CM" or Category = "M2" or Category = "P1" or   
          Category = "ZZ" then

it can be simplified by:

dim ValidValues as string
ValidValues = "CM M2 P1 ZZ"     
' don't forget to insert any 
' categories between P1 and ZZ
if (instr(1, ValidValues, Category)) > 0 then

Not only does this version not require you to go on scrolling horizontally while writing the code but is faster as well, based on simple tests I conducted using VB3 on a 486DX-66. Note that I have used a space to separate categories in ValidValues string. You may use any separator, such as semicolon, comma, etc. If you do not use a separator, the ValidValues string will become "CMM2P1ZZ" and you might get incorrect results and make the ValidValues string less readable.

Jaspreet Singh
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date