Export (0) Print
Expand All

Interaction.IIf Method

Returns one of two objects, depending on the evaluation of an expression.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static Object IIf(
	bool Expression,
	Object TruePart,
	Object FalsePart
)

Parameters

Expression
Type: System.Boolean

Required. Boolean. The expression you want to evaluate.

TruePart
Type: System.Object

Required. Object. Returned if Expression evaluates to True.

FalsePart
Type: System.Object

Required. Object. Returned if Expression evaluates to False.

Return Value

Type: System.Object
Returns one of two objects, depending on the evaluation of an expression.

The IIf function provides a counterpart for the ternary Conditional Operator: ? : in Visual C++.

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 
    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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft