Syntax Rules for Expressions

You cannot save an expression that contains a syntax error. For example: unbalanced parenthesis "2 + (2/3" , or using an operator without an operand "2 + ".
It is perfectly legal to save an expression that will have an INVALID result, such as any number divided by zero.

Syntax and notes for expressions:

  • Operators are symbols such as plus and minus signs. Operands are the things being operated on by the operators. In the expression 2 + 2, the digits "2" are operands and the "+" is an operator. 
  • Spaces between operators and operands.
    These are not required but they are recommended. The spaces will increase the clarity of your code and help you avoid errors.
  • Extra spaces are ignored.

  • Line breaks are ignored, except that they count as a space.

  • There is a precedence to the order in which mathematic operations are performed. For example, multiplication before addition. You can use parenthesis to improve clarity and to control the order of the operations. ((2 + 3) * 5).
  • Close what you open; parenthesis (...), quotation marks "...", etc.
  • Text must be enclosed in double quotation marks.
  • To display a quotation mark in text, use a doubled set of quotation marks:

    "The computer said, ""Hello World"". "

  • Text not enclosed in quotation marks is taken as the name of a variable. 2 + X.
    If the variable cannot be seen in the current scope of the expression you will get an error message.
  • VTScada text, such as tag descriptions, etc. is stored in phrases and referenced by phrase identifier key values. If you query a tag's description parameter, you will get the phrase identifier key not the text of the description. See: Multilingual Expressions
  • You cannot declare variables in expressions or assign values to variables. But you can use existing ones such as tag values and application properties.
  • FALSE is zero. TRUE is any numeric non-zero, usually 1.
  • "Invalid" is a clearly defined thing in VTScada. It means that there is no value available. Examples include the value of an I/O tag when communications are lost, division by zero, and any variable that is declared but has not had a value assigned. Invalid
    Invalid is neither TRUE nor FALSE. Any calculation with an Invalid operand will return Invalid as a result.
  • Certain text functions might return a zero-length string "" if they cannot return anything else. This isn't TRUE, FALSE or Invalid. Just one more thing to watch for.
  • Many VTScada functions are designed to work only in one of two modes, "script" or "steady state". For more detail, refer to the topic, Using Functions.