4.6.1. Declaring variables


<< Prev   Next >>

Description:

Explicitly declares a variable.

Syntax:

Var <Variable name 1> [Export] [, <Variable name 2>, …];

Parameters:

<Variable name 1>[, <Variable name 2>, …]

Specifies name(s) of declared variable(s).

Export

Optional keyword. Indicates that this variable is available when accessing the context of this module from other modules. This keyword must be specified for each declared variable separately. It is meaningless when declaring variables of separate procedures or functions.

Example:

// Example of single variable declaration
Var A Export;
Var B;

// Example of several variables declaration in a single statement
Var A, B Export;

Implicit variable declaration:

You do not have to declare variables explicitly. The first time a variable is specified before an assignment operator, it is considered implicitly declared. The variable type is determined by the type of value assigned to it. Variables that were not previously explicitly or implicitly declared cannot be used in expressions.

Variable scope:

The scope of variables depends on where they are declared in the configuration. There are three areas where variables can be declared:

  • In the variable declaration section of the managed application module. These variables are global.
  • In the variable declaration section of a module. These are module variables.
  • In a procedure or function. These variables are local.

Global variables declared with the Export keyword are available for use in executable statements, expressions, in any procedure or function of any custom module of the configuration.

Module variables are available for use in executable statements, expressions, in any procedure or function of the module where they are declared. If they are declared with the Export keyword, they are available from other modules via the context of the module where they are declared.

Local variables are available within the procedure or function where they are declared.

If a variable is defined as global, then it is visible from all the procedures and functions of any custom module of the configuration. If a variable is defined in a procedure or function, its scope is this procedure or function.

This way, if two variables with the same name are used in two different procedures of a module and the names of these variables are not declared as global, those are two different variables local within their procedures. If a variable is declared as global, any use of its name calls the same variable.

The only way to create a local variable in a procedure with a name of an already existing global variable is to declare such local variable explicitly using the Var statement.

<< Prev   Next >>

Icon/Social/001 Icon/Social/006 Icon/Social/005 Icon/Social/004 Icon/Social/002