EasyManua.ls Logo

Omron NJ Series - Page 279

Omron NJ Series
668 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
6 Programming
6-92
NJ-series CPU Unit Software User’s Manual (W501)
Application:
Use this construct to perform different actions based on the value of an integer.
Description:
If <integer_expression> matches <integer_expression_value_n>, <statement_n> is executed.
If <integer_expression> does not match any of the integer values, <statement_m> is executed.
Precautions:
CASE must always be used together with END_CASE.
Use one of the following for the <integer_expression>:
An integer or enumeration variable (example: abc)
An integer expression (example abc+def)
A function that returns an integer value (example: xyz())
You can write any of the statements on multiple lines. Separate statements with a semicolon (;).
To specify OR logic of multiple integers for <integer_expression_value_n>, separate the values
with commas. To specify a continuous range of integers, separate the start integer and the end
integer with two periods (..).
Example 1: You can specify a condition for a specific integer value, or the same condition for
multiple integer values.
Example 2: You can give an integer variable, integer expression, integer function return value,
enumeration variable, or enumeration function return value for the
<integer_expression>. An example is shown below.
Example for an Integer Enumeration Variable
CASE ColorVar OF
RED:
X := 0;
BLUE:
X := 1;
ELSE
X := 2;
END_CASE;
CASE A OF
1: X:=1;
2: X:=2;
3: X:=3;
ELSE
X:=0;
END_CASE;
A value of 1 is assigned to variable X when variable A is 1.
A value of 2 is assigned to variable X when variable A is 2.
A value of 3 is assigned to variable X when variable A is 3.
If none of the values is matched, a value of 0 is assigned to
the variable X.
CASE A OF
1: X:=1;
2,5: X:=2;
6..10: X:=3;
11,12,15..20: X:=4;
ELSE
X:=0;
END_CASE;
A value of 1 is assigned to variable X when variable A is 1.
A value of 2 is assigned to variable X when variable A is 2 or 5.
A value of 3 is assigned to variable X when variable A is between 6 and 10.
A value of 4 is assigned to variable X when variable A is 11, 12,
or between 15 and 20.
If none of the values is matched, a value of 0 is assigned to the
variable X.

Table of Contents

Other manuals for Omron NJ Series

Related product manuals