Skip to content

Variables

NetLinx provides support for several different types of variables distinguished by attributes such as scope, constancy and persistence.

Scope differentiates the two basic classes of NetLinx variables:

  • Local variable: variable declared within a subroutine or function whose scope is limited to that subroutine or function. See Local Variables for details.

  • Global variable: variable declared in the DEFINE_VARIABLE section and its scope extends throughout the module in which it is declared. See Global Variables for details.

Any variable may also be assigned the attribute CONSTANT. This declares a variable to be immutable (cannot change at run-time). The variable must be initialized as part of its declaration if this keyword is used.

The persistence of a variable is controlled through the NON_VOLATILE, VOLATILE and PERSISTENT keywords:

  • Non-volatile variables: A variable declared with the NON_VOLATILE keyword is stored in non-volatile memory. It will retain its value in the event of a system power-down, but is reset to zero if the program is reloaded. Unless specified otherwise, all variables are stored in non-volatile memory.

  • Volatile variables: A variable declared with the VOLATILE keyword is stored in volatile memory and reset to zero after either power-down or reload. Volatile memory is generally faster and more plentiful than non-volatile memory. For this reason, you should use the VOLATILE keyword when declaring large data arrays where persistence of the data is not a requirement.

  • Persistent variables: If a variable is declared with the PERSISTENT keyword, it is initialized to zero the first time the program is loaded but will retain its value after either power-down or reload. See Persistent Variables for details.

If the data type is omitted from the variable definition, the following defaults are assumed:

  • Single variables are INTEGER type
  • Arrays are CHAR type

See Also