Rockwell Automation Publication 1756-RM003N-EN-P - October 2011 673
Structured Text Programming Appendix C
Expressions
An expression is a tag name, equation, or comparison. To write an expression, use
any of the following:
• Tag name that stores the value (variable)
• Number that you enter directly into the expression (immediate value)
• Functions, such as: ABS, TRUNC
• Operators, such as: +, -, <, >, And, Or
As you write expressions, follow these general rules:
• Use any combination of upper-case and lower-case letter. For example, these
three variations of ‘AND’ are acceptable: AND, And, and.
• For more complex requirements, use parentheses to group expressions within
expressions. This makes the whole expression easier to read and ensures
that the expression executes in the desired sequence. See Determine the
Order of Execution on page 678.
In structured text, you use two types of expressions.
BOOL expression: An expression that produces either the BOOL value of
1 (true) or 0 (false).
• A bool expression uses bool tags, relational operators, and logical operators
to compare values or check if conditions are true or false. For example,
tag1>65.
• A simple bool expression can be a single BOOL tag.
• Typically, you use bool expressions to condition the execution of other logic.
Numeric expression: An expression that calculates an integer or floating-point
value.
• A numeric expression uses arithmetic operators, arithmetic functions, and
bitwise operators. For example, tag1+5.
• Often, you nest a numeric expression within a bool expression. For example,
(tag1+5)>65.
Use the table to choose operators for your expressions.
If you want to Then
Calculate an arithmetic value Use Arithmetic Operators and Functions
on page 674.
Compare two values or strings Use Relational Operators
on page 675.
Check if conditions are true or false Use Logical Operators
on page 677.
Compare the bits within values Use Bitwise Operators
on page 678.