Expression evaluator

Calculate the result of an expression with integers, decimals, numeric variables, string variables for string comparisons, arithmetic and Boolean operators, or a set of functions.

Properties

Property
Description
Expression
The expression to be calculated.
The expression can contain an unlimited number of correctly opened and closed parentheses. If the expression does not follow the correct syntax, the converter does not perform the calculation.
Mode
The direction of the dynamic link:
  • Read from the source node to the parent.
  • Write from the parent to the source node.
  • Read from the source node to the parent and write from the parent to the source node.

Source

One or more variables identified by:
{
index_number
}
placeholder
Progressive integer equal to or greater than zero. For example,
{1}
{#
placeholder_identifier
}
placeholder
String prefixed with
#
. For example,
{#speed}
TIP: Use any combination of placeholders in any order. Use any number of placeholders in the expression.

Literals

  • Boolean.
  • Integers.
  • Decimals where the decimal separator must be a point.
  • Hexadecimal numbers with the prefix
    0x
    .
  • Text such as a string delimited by double quotation marks.
    TIP: Double quotation marks repeated twice (
    ""
    ) are interpreted as an escape sequence.
  • Date and time. For example,
    2017-06-28T15:26:06.0790910
    .

Operators

Category
Operator
Associativity
Comments
Unary
Unary minus:
-
Bitwise NOT:
~
Cast operator:
(type)
Right to left
The cast operator
(type)
applies to all numeric data types and Boolean only.
Multiplicative
*
,
/
,
%
Left to right
Additive
+
,
-
Left to right
Shift
<<
,
>>
Left to right
Shift and Relational operators apply to these data types:
  • Numeric
  • DateTime
  • Duration
Relational
<
,
<=
,
>
,
>=
Left to right
Equality
==
,
!=
Left to right
Equality operators apply to these data types:
  • Numeric
  • DateTime
  • Duration
  • String
  • LocalizedText
Bitwise AND, XOR, OR
&
,
^
,
|
Left to right
Logical AND
&&
Left to right
Logical OR
||
Left to right

Data types

Data type conventions in the expression evaluator:
  • Literal integers are Int32.
  • Decimal literals are Double.
  • Numerical values are considered to be Int32.
  • Literals true and false are interpreted as Boolean.
  • The / operator always returns a Double value.
  • The % operator generates an exception when there is division by modulo zero.
  • The % operator accepts Float and Double operands.
  • All functions return a Double value except for sign, which returns an Int32 value.
The
type
of unary cast operators can be of these data types:
  • bool, Boolean
  • sbyte, SByte
  • short, Int16
  • int, Int32
  • long, Int64
  • byte, Byte
  • ushort, UInt16
  • uint, UInt32
  • ulong, UInt64
  • float, Float
  • double, Double
Operators applied to specific data types:
Operator
Operand1
Operand2
Description
Plus
DateTime
Integral number
Operand2
is interpreted as milliseconds.
Plus
Integral number
DateTime
Operand1
is interpreted as milliseconds.
Plus
DateTime
TimeZone (Struct)
Operand2
is interpreted as minutes (TimeZone.Offset).
Plus
TimeZone (Struct)
DateTime
Operand1
is interpreted as minutes (TimeZone.Offset).
Plus
TimeZone
Integral number
Operand1
is interpreted as minutes (TimeZone.Offset).
Operand2
is interpreted as minutes.
Plus
Integral number
TimeZone
Operand1
is interpreted as minutes.
Operand2
is interpreted as minutes (TimeZone.Offset).
Minus
DateTime
Integral number
Operand2
is interpreted as milliseconds.
Minus
DateTime
TimeZone (Struct)
Operand2
is interpreted as minutes (TimeZone.Offset).
Minus
TimeZone
Integral number
Operand1
is interpreted as minutes (TimeZone.Offset).
Operand2
is interpreted as minutes.

Functions

Functions for use in the expression evaluator:
Function
Syntax
Description
Return data type
max
max(
value1
,
value2
,
value3
, ...)
Returns the greatest value.
Double
min
min(
value1
,
value2
,
value3
, ...)
Returns the lowest value.
Double
avg
avg(
value1
,
value2
,
value3
, ...)
Returns the average of the given values.
Double
abs
abs(
value
)
Returns the absolute value of the given number.
Double
trunc
trunc(
value
)
Returns the integer part of a decimal number.
Double
ceil
ceil(
value
)
Returns the approximated value by excess.
Double
floor
floor(
value
)
Returns the approximated value by defect.
Double
round
round(
value
)
Returns the approximation to the nearest integer.
Double
sqrt
sqrt(
value
)
Returns the square root of the given number.
Double
sign
sign(
value
)
Checks if the given floating point number is negative. Returns
0
if true or
1
if false.
Int32
like
like(
string_value
,
pattern
)
Applies only to String, QualifiedName, and LocalizedText
data types.
Returns
true
if the
string_value
parameter matches the
pattern
.
The
pattern
accepts the
%
wildcard at the beginning or at the end.
Examples:
  • like("motor23", "motor%")
    evaluates
    true
  • like("machine_2", "motor%")
    evaluates
    false
Boolean
isempty
isempty(
variable
)
Checks if a given NodeID, String, LocalizedText, or DataTime is empty.
Boolean
if
if(
condition
,
value_if_true
,
value_if_false
)
Checks if the
condition
is true and returns either
value_if_true
or
value_if_false
The syntax must meet these requirements:
  • For
    value_if_true
    and
    value_if_false
    , use parameters of the same data type.
  • For Boolean values, use lowercase
    true
    or
    false
    .
  • For colors, link to color values or use the
    0x
    AA
    RR
    GG
    BB
    syntax, where:
    • 0x
      is the hex notation
    • AA
      is the alpha channel (transparency)
    • RR
      is the red channel
    • GG
      is the green channel
    • BB
      is the blue channel
value_if_true
data type
left_of
left_of(string, pattern)
Returns the substring on the left of the first occurrence of the regular expression pattern.
IMPORTANT: Do not use wildcards in patterns.
String
right_of
right_of(string, pattern)
Returns the substring on the right of the first occurrence of the regular expression pattern.
IMPORTANT: Do not use wildcards in patterns.
String
like(string_value, pattern)
Applies only to
String
,
QualifiedName
and
LocalizedText
data types.
Returns true if the
string_value
parameter matches the given
pattern
.
The
pattern
accepts the
%
wildcard at the beginning or at the end.
Examples
  • like("motor23", "motor%")
    evaluates
    true
  • like("machine_2", "motor%")
    evaluates
    false

Output

The resulting value of the expression.

Examples

Return the absolute value of a variable
If variable value is higher than 40, toggle the visibility of a graphic object
If variable value is higher than 50, change the background color of a graphic object to blue
If variable value is between 30 and 40, blink the green led object when active
If text box border color is red, enable the button
If the label text equals to "WARNING", change the label text color to red
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.