IIf (function)

Syntax

IIf(condition,TrueExpression,FalseExpression)

Description

Returns TrueExpression if condition is True; otherwise, returns FalseExpression.

Comments

Both expressions are calculated before IIf returns.

The IIf function is shorthand for the following construct:

  If condition Then
    variable = TrueExpression
  
Else
    variable = FalseExpression
  
End If

Example

Sub Main() 
  s$ = "Car"
  MsgBox "You have a " & IIf(s$ = "Car","nice car.","nice non-car.")
End Sub

See Also

Choose (function); Switch (function); If...Then...Else (statement); Select...Case (statement).

More information

I