Structured Text Components: 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)
  • String literal that you enter directly into the expression (
    CompactLogix
    5380,
    CompactLogix
    5480,
    ControlLogix
    5580,
    Compact GuardLogix
    5380, and
    GuardLogix
    5580 controllers
    only)
  • Functions, such as: ABS, TRUNC
  • Operators, such as: +, -, <, >, And, Or
Follow these guidelines for writing expressions:
  • Use any combination of upper-case and lower-case letter. For example, these 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.
Use these expressions for structured text:
BOOL expression:
An expression that produces 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, 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.
  • Nest a numeric expression within a BOOL expression. For example, (tag1+5)>65.
String expression:
An expression that represents a string
  • A simple expression can be a string literal or a string tag
Use this table to select the operators for expressions.
If
Use
Calculating an arithmetic value
Arithmetic operators and functions
Comparing two values or strings
Relational operators
Verifying if conditions are true or false
Logical operators
Comparing the bits within values
Bitwise operators
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.