A control structure that directs program execution based on the value of a test expression (usually a variable).
CHOOSE CASE testexpression CASE expressionlist statementblock { CASE expressionlist statementblock . . . CASE expressionlist statementblock } CASE ELSE statementblock } END CHOOSE
Parameter |
Description |
---|---|
testexpression |
The expression on which you want to base the execution of the script |
expressionlist |
One of the following expressions:
|
statementblock |
The block of statements you want PocketBuilder to execute if the test expression matches the value in expressionlist |
At least one CASE clause is required. You must end a CHOOSE CASE control structure with END CHOOSE.
If testexpression at the beginning of the CHOOSE CASE statement matches a value in expressionlist for a CASE clause, the statements immediately following the CASE clause are executed. Control then passes to the first statement after the END CHOOSE clause.
If multiple CASE expressions exist, then testexpression is compared to each expressionlist until a match is found or the CASE ELSE or END CHOOSE is encountered.
If there is a CASE ELSE clause and the test value does not match any of the expressions, statementblock in the CASE ELSE clause is executed. If no CASE ELSE clause exists and a match is not found, the first statement after the END CHOOSE clause is executed.
Example 1 These statements provide different processing based on the value of the variable Weight:
CHOOSE CASE Weight
CASE IS<16
Postage=Weight*0.30
Method="USPS"
CASE 16 to 48
Postage=4.50
Method="UPS"
CASE ELSE
Postage=25.00
Method="FedEx"
END CHOOSE
Example 2 These statements convert the text in a SingleLineEdit control to a real value and provide different processing based on its value:
CHOOSE CASE Real(sle_real.Text)
CASE is < 10.99999
sle_message.Text = "Real Case < 10.99999"
CASE 11.00 to 48.99999
sle_message.Text = "Real Case 11 to 48.9999
CASE is > 48.9999
sle_message.Text = "Real Case > 48.9999"
CASE ELSE
sle_message.Text = "Cannot evaluate!"
END CHOOSE