Operator

If


Description

A trinary operator that evaluates an expression and returns results when it is True or False.

Usage

If(condition, <result when expression is true>, <result when expression is false>)

Part

Description

condition

Required. A boolean, numeric, or string expression that evaluates to True or False.

result when expression is true

Required. This result is returned when the expression evaluates to True.

result when expression is false

Required. This result is returned when the expression evaluates to False.

Notes

The return type is the common type between the two result values. For example, If an Int8 and an Int32 are used as result values, the result type will actually be Int32. Having no common type results in a Type Mismatch compile error.

This operator uses the same evaluation rules as a normal If...Then...Else statement. Only the result that is needed gets evaluated.

Sample code

This code outputs "Big number":

Var myInteger As Integer = 42
MessageBox(If(myInteger > 40, "Big number", "Small number"))

Compatibility

All project types on all supported operating systems.