Public Function IIf( _
ByVal Expression As Boolean, _
ByVal TruePart As Object, _
ByVal FalsePart As Object _
) As Object
Parameters
Expression
Required. Boolean. The expression you want to evaluate.
TruePart
Required. Object. Returned if Expression evaluates to True.
FalsePart
Required. Object. Returned if Expression evaluates to False.
Remarks
The IIf function provides a counterpart for the ternary Conditional Operator: ? : in Visual C++.
Example
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".
Visual Basic
Function checkIt(ByVal testMe As Integer) As String
Return CStr(IIf(testMe > 1000, "Large", "Small"))
End Function
Note that if Option Strict is On, you must use the CStr keyword to explicitly convert the return from Object to String.
No comments:
Post a Comment