Promotic

Dim - statement of language VBScript

Description:
Declares variables.
Syntax:

Dim name [([dimensions])][, name [([dimensions])]] ...

name Name of the variable
dimensions Dimensions of an array variable up to 60 multiple dimensions may be declared. The subscripts parameter uses the following syntax:
upper_index[, upper_index] ...
The lower array index is always 0.
Note:
Variables declared with Dim in the procedure are available only within the procedure.

You can also use the statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements of the array. If you try to redeclare a dimension for an array variable whose size was explicitly specified in a Dim statement, an error occurs.

Caution:
- Using explicitly specified array, for example Dim a(2), will have this 1-dimensional array 3 (not 2 !) items: a(0), a(1) and a(2).
- If the array is defined explicitly, the dimension must be defined as constant (not variable). Therefore it is not possible to enter for example Dim a(n).
- The 1-dimensional array can be created also by the VBScript Array function.


Tip: If you use the Dim statement in a procedure, then you usually put it at the beginning of the procedure.

In the PROMOTIC system scripts, it is possible to create a variable also by the #pragma variable directive, that allows to create a varible with special predefined value (e.g. object referrence, text in current language, etc.). For a varible created such way the statement Dim and Set are not used.

For similar purpose in the JavaScript language is used the statement var.
See also:
- Set
Example1:
Select and copy to clipboard

' Declare two variables
Dim nVar, nNum
' Declare an array with 10 elements
Dim Names( 9)
' Declare a dynamic array
Dim Names()
Dim nVar, nNum 'Declare two variables
Dim Names(9) 'Declare an array with 10 elements
Dim Names() 'Declare a dynamic array
Example2:
Creates and fills a 2-dimensional array
Select and copy to clipboard

Dim arr( 2,3)
arr(0, 0) = 10
arr(1, 0) = 20
arr(2, 0) = 30
arr(0, 1) = 5
arr(0, 2) = 15
' ...
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.