SELECT Commands
The SELECT CASE statement executes one of several groups of statements, depending on the value of an expression.
SELECT CASE Subcommands
SELECT CASE value
Executes one of several groups of statements, depending on the value of an expression. 'value' is the expression to be tested. It can be a number or string variable or a complex expression.
CASE testexp [[, testexp] …]
'testexp' (or test-n) is the value that is to be compared against. It can be:
- A single expression (i.e.
34,"string"orPIN(4)*5) to which it may equal - A range of values in the form of two single expressions separated by the keyword
TO(i.e.5 TO 9or"aa" TO "cc") - A comparison starting with the keyword
IS(which is optional). For example:IS > 5,IS <= 10.
When a number of test expressions (separated by commas) are used the CASE statement will be true if any one of these tests evaluates to true.
CASE ELSE
If 'value' cannot be matched with a 'testexp' it will be automatically matched to the CASE ELSE. If CASE ELSE is not present the program will not execute any <statements> and continue with the code following the END SELECT.
END SELECT
Concludes the SELECT CASE statement. When a match is made the <statements> following the CASE statement will be executed until END SELECT or another CASE is encountered when the program will then continue with the code following the END SELECT.
Each SELECT CASE must have one and one only matching END SELECT statement. Any number of SELECT … CASE statements can be nested inside the CASE statements of other SELECT … CASE statements.