Expression Data Types

Strings in Expressions

Certain expressions may involve working with text as strings. The syntax for including a string is one of the following:

  • "Hello World" is a constant string delimited with double quotation marks.
  • $"Hello World"$ is a constant string enclosed between $" and "$ characters.
The $" "$ syntax has a higher priority in the expression, meaning it be used to encapsulate other double-quote values. For example, the expression x=$"This is my "special text""$ will resolve as the string This is my "special text".

String Comparison: When comparing strings or numeric data coming from the server as strings, the comparison is based on the character order. For example, the expression x="world" > "hello" evaluates as true, because the character "w" comes after the character "h" in alphabetical order.

Sometimes, the string comparison may be misleading. Example: x="20" > "100" evaluates as true because the character "2" comes after the character "1" in the character table. Of course, if there were an expectation of a numeric comparison, 20 < 100 and the above expressions might seem to be evaluated incorrectly, but they are not.

Data Type Conversion: Expressions allow calculations on incoming data. Expression variable can provide data in one or more data types, such as "float," "long," "integer," or "string." Some data may have numeric data as a string. For example, the numeric value 20 may be presented as the string "20" (character "2" followed by character "0"), leading to an incorrect expression evaluation (see the string section above).

The workaround is to add a zero (0)to each of the tags to enable the logic operators to work properly. For example:

x=({{JC.N1OPC.1.0\HDQTRS\sys2\ad-3.Present Value}}+0) > ({{JC.N1OPC.1.0\HDQTRS\sys2\ad-4.Present Value}}+0)

Some of the functions provided in the expression editor use numeric type parameters. When possible, the expression editor automatically converts the string into a number. For example, the string "20" is automatically converted to the number 20. However, the automatic conversion is impossible if the string contains alphabetic characters or symbols. For example, the string "20hello" cannot be converted into a number.

Even if the string contains only numeric characters and valid symbols, there may still be cases where an automatic conversion is not possible. For example, the string "123.45.23" cannot be converted into a number because it contains two decimal separators.

Explicit Data Type Conversions

Each value can be explicitly converted to a specific data type by adding the target data type name in parentheses. For example

(int){{variable}}

The available data types are:

  • sbyte
  • byte
  • short
  • ushort
  • int
  • uint
  • long
  • ulong
  • float
  • double
  • decimal
  • char
  • string

Numeric constants can specify a target data type by adding a suffix. For example, 10D represents the number 10 as a double.

  • D (double)
  • F (float)
  • L (long)
  • M (decimal)
  • U (ulong)