IIf
Value = IIf ( Test AS Boolean , TrueExpression , FalseExpression )
Value = If ( Test AS Boolean , TrueExpression , FalseExpression )
Evaluate the
Test expression, and return
TrueExpression if this expression is
TRUE,
or
FalseExpression if this expression is
FALSE.
BE CAREFUL!
Contrary to
IF, or the C/Perl
?
operator, both
TrueExpression and
FalseExpression are evaluated, whatever the value of
Test is.
Examples
Dim X As Integer = 7
PRINT If((X MOD 2) = 0, "even", "odd")
' Never do the following in real code, because it is not translatable!
Dim X As Integer = 7
PRINT "You have " & X & " message" & If(X <> 1, "s", "") & " waiting."
You have 7 messages waiting.
Dim X As Integer = 7
PRINT If((X MOD 2) = 1, "odd", 1 / 0)
See also