100BBasic instructions
7.8 Program control
S7-1200 Programmable controller
System Manual, 11/2011, A5E02486680-05
211
7.8.3
CASE statement
Table 7- 95 Elements of the CASE statement
SCL
Description
CASE "Test_Value" OF
"ValueList": Statement[; Statement, ...]
"ValueList": Statement[; Statement, ...]
[ELSE
Else-statement[; Else-statement, ...]]
END_CASE;
The CASE statement executes one of several
groups of statements, depending on the value
of an expression.
Table 7- 96 Parameters
Parameter
Description
"Test_Value"
Required. Any numeric expression of data type Int
"ValueList"
Required. A single value or a comma-separated list of values or ranges of values. (Use two
periods to define a range of values: 2..8) The following example illustrates the different
variants of the value list:
1: Statement_A;
2, 4: Statement _B;
3, 5..7,9: Statement _C;
Statement
Required. One or more statements that are executed when "Test_Value" matches any value
in the value list
Else-statement
Optional. One or more statements that are executed if no match with a value of the
"ValueList" stated matches
The CASE statement is executed according to the following rules:
●
The selection expression must return a value of the type Int.
●
When a CASE statement is processed, the program checks whether the value of the
selection expression is contained within a specified list of values. If a match is found, the
statement component assigned to the list is executed.
●
If no match is found, the program section following ELSE is executed or no statement is
executed if the ELSE branch does not exist.
CASE statements can be nested. Each nested case statement must have an associated
END_CASE statement.
CASE var1 OF
1 : var2 := "A";
2 : var2 := "B";
CASE var1 OF
65..90: var2 := "UpperCase";
97..122: var2 := "LowerCase";
END_CASE
ELSE
var1:= "SpecialCharacter";