### IIF (expression, truePart, falsePart)

Basic and Crystal syntax.

##### Argument

- expression is a Boolean expression.
- truePart is the value returned if expression is True. It can be any simple type (Number, Currency, String, Boolean, Date, Time or DateTime) or range type (Number Range, Currency Range, String Range, Date Range, Time Range or DateTime Range), but it may not be an array.
- falsePart is the value returned if expression is False. It must be of the same type as truePart.

##### Returns

truePart if expression is True and falsePart if expression is False. The type of the returned value is the same as the type of truePart and falsePart.

##### Action

IIF returns one of two parts, depending on the evaluation of the expression.

##### Typical uses

- IIF can be used as an alternative to the If/Then/Else control structure in some situations.
- One situation where IIF may be better than a control structure is when writing record selection formulas so that they can be pushed down to the database server. See Switch (expr1, value1, expr2, value2, ..., exprN, valueN) for an example and Advanced record selection formulas for an explanation of the techniques involved.

##### Examples

The following examples are applicable to both Basic and Crystal syntax:

`IIF ({Orders.Order Amount} > 10000, "large order", "standard order")`

Returns the String value "large order" if {Orders.Order Amount} is more than $10,000 and the String value "standard order" otherwise.

You can insert a formula field that represents the order amount if the payment has been made already, and is 0 otherwise:

Rem Basic syntax
formula = IIF ({Orders.Payment Received}, {Orders.Order Amount}, 0)
//Crystal syntax
IIF ({Orders.Payment Received}, {Orders.Order Amount}, 0)

##### Comments

- This function is designed to work like the Visual Basic function of the same name. A difference is that the function does not return a Variant and thus truePart and falsePart must have the same type.
- Every argument of the IIF function is evaluated before the result is returned. Thus, you should watch out for undesirable side effects when using IIF. For example, if falsePart results in division by zero, an error will occur, even if expression is True and so truePart is returned.

###### Related topics

Choose (index, choice1, choice2, ..., choiceN)

Switch (expr1, value1, expr2, value2, ..., exprN, valueN)

Select statements (Basic syntax)

Select expressions (Crystal syntax)

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com