Instance Variables - VAR_INST

TwinCAT creates a VAR_INST variable of a method not on the method stack like VAR variables but on the stack of the function block instance. This means that the VAR_INST variable behaves like other variables of the function block instance and is not reinitialized each time the method is called.

VAR_INST variables are only allowed in methods of a function block, and access to such a variable is only available within the method. You can monitor the variable values of instance variables in the declaration part of the method.

Instance variables cannot be extended with an attribute keyword.

Example:

METHOD MethLast : INT
VAR_INPUT
    nVar  : INT;
END_VAR
VAR_INST
    nLast : INT := 0;
END_VAR
MethLast := nLast;
nLast    := nVar;

See also: