The features on this page require a GENESIS64 Advanced license and are not available with GENESIS64 Basic SCADA . |
The Expression Editor supports Switch statements. These statements can replace long series of IF-THEN statements. They are used to covert single expression values to other values, most often integer values to strings. The syntax is very similar to that used by Transact-SQL.
The syntax is as follows:
CASE input_expression
WHEN when_constant_expression THEN result_expression [ 1...n ]
[ ELSE else_result_expression ]
END
Where:
input_expression is any standard expression, such as an external variable (like {{my variable}}) or combination of functions and variable(s).
when_constant_expression can be any constant or constant expression, such as: 1 + 2, “my text”, etc. All WHEN expressions values must have the same data type – either numbers or strings – and must be unique within CASE statement.
result_expression and else_result_expression are any standard expression text.
The statement will try to match the input expression to one of the WHEN values. If a match is found, the statement will return the value in the following THEN expression. Multiple WHEN statements can be called in a row to have them all return the same THEN value.
If no WHEN value can be matched, the value in the ELSE expression will be returned. The ELSE section is optional. When it is omitted, an empty value will be used.
Example expressions using the switch statement:
CASE {{my tag}}
WHEN 1
WHEN 2 THEN "A"
WHEN 3 THEN "B"
WHEN 8
WHEN 9
WHEN 10 THEN "C"
ELSE "D"
END
CASE {{my tag}}
WHEN "A"
WHEN "B" THEN 0
WHEN "C"
WHEN "D" THEN 1
ELSE 2
END
CASE {{my tag}} - 10
WHEN 1
WHEN 2 THEN {{my second tag}}
WHEN 3 THEN {{my second tag}} + {{my tag}}
WHEN 8
WHEN 9
WHEN 10 THEN {{my third tag}}
END
See Also: