CHOOSE CASE

Description

A control structure that directs program execution based on the value of a test expression (usually a variable).

Syntax

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:

  • A single value

  • A list of values separated by commas (such as 2, 4, 6, 8)

  • A TO clause (such as 1 TO 30)

  • IS followed by a relational operator and comparison value (such as IS>5)

  • Any combination of the above with an implied OR between expressions (such as 1, 3, 5, 7, 9, 27 TO 33, IS >42)

statementblock

The block of statements you want PocketBuilder to execute if the test expression matches the value in expressionlist

Usage

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.

Examples

Example 1

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

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