684 Rockwell Automation Publication 1756-RM003N-EN-P - October 2011
Appendix C Structured Text Programming
CASE...OF
Use CASE to select what to do based on a numerical value.
Operands:
Structured Text
Description: The syntax is described in the table.
See the table on page 686
for valid selector values.
Operand Type Format Enter
Numeric_
expression
SINT
INT
DINT
REAL
Tag
expression
Tag or expression that evaluates to a number
(numeric expression)
Selector SINT
INT
DINT
REAL
Immediate Same type as numeric_expression
If you use REAL values, use a range of values for a selector
because a REAL value is more likely to be within a range of
values than an exact match of one, specific value.
CASE numeric_expression OF
selector1: statement;
selectorN: statement;
ELSE
statement;
CASE numeric_expression OF
Specify as many alternative
selector values (paths) as
you need.
selector1 : <statement>;
.
.
.
Statements to execute when
numeric_expression = selector1
selector2 : <statement>;
.
.
.
Statements to execute when
numeric_expression = selector2
selector3 : <statement>;
.
.
.
Statements to execute when
numeric_expression = selector3
optional
ELSE
<statement>;
.
.
.
Statements to execute when
numeric_expression ≠any selector
END_CASE;