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

##### Arguments

- index is a Number or numeric expression that specifies the index of the choice. It should be between 1 and the number of available choices. If it is out of bounds, Choose returns a default value. (The default value returned depends on the type of the choices. For example, if the choices are of Number type, the default value is 0 and if the choices are of String type, the default value is the empty string ("").)
- choice is one of the choices to choose from. All choices must be of the same type. A choice 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.

##### Returns

A value from the given list of choices. The type of the returned value is the same as the type of the choices.

##### Action

Choose returns a value from the list of choices based on the value of index. For example, if index is 1, it returns choice1 and if index is 2 it returns choice2 and so forth.

##### Typical uses

- Choose can be used instead of the If-Then-Else operators or the Select control structures in some situations. For example, if you are mapping an index value to a String value, it can be simplest to use Choose.
- One situation where Choose 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) function for an example of this.

  See Advanced record selection formulas for an explanation of the techniques involved.

##### Examples

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

`Choose (3, "Poor", "Fair", "Good", "Excellent")`

Returns the String "Good".

`Choose (2, 10 To 20, 100 To 200, 60 To 70)`

Returns the Number Range value 100 To 200.

If a company has fiscal year starting July 1 (the 3rd calendar quarter) and it wants to print the fiscal quarter of each order date:

Rem Basic syntax
formula = Choose (DatePart ("q", {Orders.Order Date}), _
"third fiscal quarter", "fourth fiscal quarter", _
" first fiscal quarter", "second fiscal quarter")
//Crystal syntax
Choose (DatePart ("q", {Orders.Order Date}),
"third fiscal quarter", "fourth fiscal quarter",
"first fiscal quarter", "second fiscal quarter")

If {Orders.Order Date} is February 18, 1996, then the DatePart function call returns 1 since this date is in the first calendar quarter. Thus, the first choice value, namely the String value "third fiscal quarter" is returned by the formula.

##### 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 all the choices must have the same type.
- Every argument of the Choose function is evaluated before the choice is returned. Thus, you should watch out for undesirable side effects when using Choose. For example, if one of the choice expressions results in division by zero, an error will occur, even if that choice is not the choice that is returned by the Choose function.

###### Related topics

IIF (expression, truePart, falsePart) function

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

If-Then-Else operators

Select statements (Basic syntax)

Select expressions (Crystal syntax)

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