Chapter 8. Structured Text (ST) Programming
GFK-2950C
February 2018
375
8.2.5
CASE Statement
The CASE …. OF construct offers conditional executi
on of statement lists. It uses the value of an ST
integer expression to determine whether to execute a statement list. The statement list to be
executed can be selected from multiple statement lists, depending on the value of the associated
integer expression.
Conditions can be expressed as a single value, a list of values, or a range of values. The single-value,
list of values, or range forms can be used by themselves or in combination. The optional ELSE
keyword can be used to execute a statement list when the associated value does not meet any of
the specified conditions.
You can have a maximum of 1024 cases in a single CASE … OF construct. Additional cases can be
handled by adding the ELSE keyword to the construct and specifying a nested CASE … OF constru
ct
or an IF … THEN construct after the ELSE.
The number of nested CASE … OF constructs and the number of levels are limited by the memory in
your computer.
The number of constants and constant ranges in a single conditional statement is limited by the
memory in your computer.
Format
CASE Integer_Expression OF
Int1:
(*Single Value*)
StatementList_1;
Int2,Int3,Int4:
(*List of Values*)
StatementList_2;
Int5..Int6:
(*Range of Values*)
StatementList_3;
[ELSE
(*Optional*)
StatementList_Else;]
END_CASE;
Where:
Integer_Expression
An ST expression that resolves to an integer (INT, DINT or UINT)
value.
Int
A constant integer value.
StatementList_1 …
StatementList_n
Structured Text statements.
Operation
The Int values are compared to Integer_Expression. The statement list following the first Int value
that matches Integer_Expression is executed. If the optional ELSE keyword is used and no Int value
matches Integer_Expression, the statement list following ELSE is executed. Otherwise, no statement
list is executed.
Requirements for Conditional Statements
All constants must be of type INT, DINT or UINT.
In range declarations, the beginning value must be less than the ending value (reading from left
to right). For example, 10..3 and 5..5 are invalid.
Overlapping values in different case conditions are not allowed. For example, 5..10 and 7 cannot
be specified as conditions in the same CASE … OF construct.
Summary of Contents for PACSystems RX7i
Page 357: ......
Page 466: ...Chapter 9 Diagnostics GFK 2950C February 2018 451...