Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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
ProcessEmployee
Endif




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
ProcessEmployee
endif




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.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date