User Tools

Site Tools


choose_return_chosen_value_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== CHOOSE (return chosen value) ====== Previous pageReturn to chapter overviewNext page
CHOOSE( expression ,value, value [,value…] )
condition [,truevalue, falsevalue ]

blk2blue.jpg

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 ParametersReturn Data Type
LONG                      LONG
DECIMAL or LONG           DECIMAL
STRING                    STRING
DECIMAL, LONG, or STRING  DECIMAL
anything else             REAL

Note: A common problem is mixing STRING's and Numbers will convert the Strings to numbers.

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)
?MyControl{PROP:Hide} = CHOOSE(SomeField = 0)         !Also Returns 1/0

!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')

!Mixes STRINGs and DECIMAL will NOT work as intended. Will convert 'No Pay' to Decimal 0,
CHOOSE(Salary=0,'No Pay',Salary * .05 )  

See Also:

INLIST

choose_return_chosen_value_.htm.txt · Last modified: 2024/11/01 01:31 by carlbarnes