CHOOSE (return chosen value)

Top  Previous  Next

 

 

CHOOSE(

| expression ,value, value [,value...] | )

 

 

| condition [,truevalue, falsevalue ] |

CHOOSE

Returns the chosen value from a list of possible values.

expression

An arithmetic expression which determines which value parameter to return. This expression must resolve to a positive integer.

value

A variable, constant, or expression for the procedure to return.

condition

A logical expression which determines which of the two value parameters to return. If no truevalue or falsevalue parameters are present, one (1) is returned when the expression is true, and zero (0) is returned when the expression is false.

The CHOOSE procedure evaluates the expression or condition and returns the appropriate value parameter. If the expression resolves to a positive integer, that integer selects the corresponding value parameter for the CHOOSE procedure to return. If the expression evaluates to an out-of-range integer, then CHOOSE returns the last value parameter.

When the condition evaluates as true, then CHOOSE returns the truevalue parameter. When the condition evaluates to false, then CHOOSE returns the second falsevalue parameter. If no value parameters are present, CHOOSE returns one (1) for true, and zero (0) for false.

The return data type is dependent upon the data types of the value parameters:

All Value Parameters       Return Data Type

 LONG                      LONG

 DECIMAL or LONG           DECIMAL

 STRING                    STRING

 DECIMAL, LONG, or STRING  DECIMAL

 anything else             REAL

 

Return Data Type:

LONG, DECIMAL, STRING, or REAL

Example:

CHOOSE(4,'A','B','C','D','E')  returns 'D'

CHOOSE(1 > 2,'A','B')          returns 'B'

CHOOSE(1 > 2)                  returns zero (0)

 

!Hide or unhide control, based on the value in SomeField:

?MyControl{PROP:Hide} = CHOOSE(SomeField = 0,TRUE,FALSE)

 

!VIEW filter to select "overweight" people of both sexes

MyView{PROP:Filter} = 'Weight > CHOOSE(Sex = ''M'',250,200)'

 

CHOOSE(Date % 7 + 1,'Sunday','Monday','Tuesday','Wednesday', |

                          'Thursday','Friday','Saturday')

CHOOSE(Date % 7 + 1,'Sun','Mon','Tue','Wed','Thu','Fri','Sat')

 

CHOOSE(Date % 7 % 6 + 1,'Weekend','Weekday')

CHOOSE(INRANGE(Date % 7,1,5),'Weekend','Weekday')

 

CHOOSE(INLIST(Emp:Sex,'M','F'),'Male','Female','Unknown')

 

 

See Also:

INLIST