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 26, 1999

Avoid IIf Inefficiencies

The IIf function-which returns one of two values determined by logical test-has this syntax: IIf(Expression, TruePart, FalsePart). At first, it might seem like an ideal shortcut for an If...Else...End If block. However, IIf is designed to execute both the True part and the False part. To verify, copy this into your Debug window and press enter:

 
? IIf(True, MsgBox("True Part"), MsgBox("False Part"))

Obviously, it's extremely inefficient-and possibly error-inducing-to place functions in the True and False parts of IIf, because they are both executed. In general, always use a standard If...Else...End If block instead.

William Wen
 
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