Returns one of two objects, depending on the evaluation of an expression.
Public Function IIf( _ ByVal Expression As Boolean, _ ByVal TruePart As Object, _ ByVal FalsePart As Object _ ) As Object
Note The expressions in the argument list can include function calls. As part of preparing the argument list for the call to IIf, the Visual Basic compiler calls every function in every expression. This means that you cannot rely on a particular function not being called if the other argument is selected by Expression.
This example uses the IIf function to evaluate the TestMe
parameter of the CheckIt
procedure and returns the word "Large" if the amount is greater than 1000; otherwise, it returns the word "Small".
Function CheckIt (ByVal TestMe As Integer) As String CheckIt =IIf(
TestMe > 1000,
"Large",
"Small")
End Function
Choose Function | If...Then...Else Statements | Select...Case Statements | Switch Function