This documentation is archived and is not being maintained.

IIf Function

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


Required. Boolean. The expression you want to evaluate.
Required. Object. Returned if Expression evaluates to True.
Required. Object. Returned if Expression evaluates to False.


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


Namespace: Microsoft.VisualBasic

Module: Interaction

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Choose Function | If...Then...Else Statements | Select...Case Statements | Switch Function