Difference between revisions of "If"

From Xojo Documentation

 
Line 35: Line 35:
 
<rbcode>
 
<rbcode>
 
Var myInteger As Integer = 42
 
Var myInteger As Integer = 42
MessageDialog.Show(If(myInteger > 40, "Big number", "Small number"))
+
MessageBox(If(myInteger > 40, "Big number", "Small number"))
 
</rbcode>
 
</rbcode>
  

Latest revision as of 21:24, 29 August 2019

Operator

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 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"))

See Also

If...Then...Else