Variables are containers. Any object (including a null-value) can be assigned to a variable, and that object becomes the variable value. Initially, the variable value is a null-value.
Local variables are local to the code section (function/procedure/entry) instance (invocation) where they were created. All their values are destroyed when the code section exits (returns).
To declare variables, use the var keyword and the list of variable names:
It is possible to declare a local variable and immediately assign it some value, using an initial value expression:
Each code section can contain several var declarations. Variables should be used after they are declared (later in the code section code).
var myCount; // the myCount variable is created myCount = 3; // the numeric value 3 is assigned to it myCount = myCount + 2; // myCount variable value changed to 5 myCount = "Service"; // myCount variable value changed to a string
Alternatively, if the code section contains no explicit var declaration, any name used in any code section operator which is not declared as a procedure or function name, and which is not matching a built-in procedure or function name declares a variable with this name.
myCount = 3; // the myCount variable is created and // the numeric value 3 is assigned to it myCount = myCount + 2; // myCount variable value changed to 5 myCount = "Service"; // myCount variable value changed to a string
Note: declaring a variable inside some "block operator" (such as the if or loop operator) declares this variable only inside this "block operator".
"Task variables" are stored in a dictionary unique for each Task ("invocation") created, and they can be used in all code sections, after being declared as Task variables. The Task variables dictionary is destroyed when the Task completes.
The Task variables are declared using the same var keyword and the variable name list, but these declarations should be placed outside any code section, and they should not contain any initial value expressions.
The alternative way to use the "task variables" is to access the Task variable dictionary directly, using the Vars() built-in function.