CHOOSE(expression, value,... , value, elsevalue)

expressionAn arithmetic expression that results in a positive integer and determines which value parameter to return.
valueThe values to return. There may be as many value parameters as necessary to specify all the expected values of the expression. This may be any expression or action.
elsevalueThe value to return when the expression returns an out-of-range value. The last parameter is always the elsevalue.
Return:CHOOSE returns a single value.

The CHOOSE function evaluates the expression and returns the value parameter whose ordinal position in the list of parameters corresponds to the result of the expression. If none match, it returns the elsevalue. All values and the elsevalue must be of the same type.


MyExp := 1+2;
MyChoice := CHOOSE(MyExp,9,8,7,6,5); // returns 7
MyChoice2 := CHOOSE(MyExp,1,2,3,4,5);  // returns 3
MyChoice3 := CHOOSE(MyExp,15,14,13,12,11);  // returns 13

IntRate:= 6.5;
RateRating := CHOOSE(IntRate,'Great','Good','Pretty Good','Fair','Fair','High','High','High','High','Invalid');
 // RateRating receives 'High' if the IntRate is between 6 and 9

See Also: CASE, IF, MAP