Purpose
"Immediate if" valuates the expression and returns one of two possible values.
IIf can only be used to return either of two values rather than directing programmatic flow. The return type of IIf is the same as that of the value that is returned.
Syntax
IIf (ConditionalExpression, TrueVal, FalseVal)
The TrueVal and FalseVal arguments can be of any type. These arguments do not need to be the same data type.
Example
Sub Main()
Dim i As Integer
For i = 1 to 10
Print "the value of i is";
IIf(i<=5, "less than or equals", "greater than"); "5"
Next i
End Sub
|