The Ilf Function

The peculiarly named IIf function is quite similar to an If..Then...Else statement. The first parameter is an expression that must evaluate to a Boolean value. The second parameter is the value the function returns if the expression is True, and the third parameter is the value the function returns if the expression is False. The syntax is:

IIf([Expression], [Return Value if True], [Return Value if False]

For example, assume a variable named intHeight previously was declared and assigned a person's height in inches. Anyone over 78 inches is too tall to fit inside a car, so the following function would return a string "too tall" or "not too tall" depending on the value of intHeight:

Dim strMsg strMsg = IIf(intHeight > 78, "Too tall", "Not too tall") Debug.Write strMsg

Was this article helpful?

0 0

Post a comment