PreserveVariables (Preserve Variables)

The PreserveVariables instruction is used to retain in memory the values for all variables declared by the Dim or Public statements.

Syntax

PreserveVariables

Remarks

The PreserveVariables instruction is placed in the declarations section of the program prior to the BeginProg instruction. When PreserveVariables is present in a program, the values of variables will not be reinitialized after a recompile (due to power loss, Constant Table change, File Control restart, etc.), provided there are no changes to the declaration of variables (Public, Dim, local variables in functions), or to data table fields. Hence, if a program is run with the same variables as the previous running program, variables’ values are preserved if the program is run with the option to retain data (Do not erase data files). If the Erase data files option is chosen, the variables are reinitialized.

NOTE: PreserveVariables preserves values that have been written to variables on the main scan interval. It does not preserve intermediate values that are held in memory, such as the temporary values used to calculate an average over an output interval.