Dim Statement

Declares variables and allocates storage space.

Syntax

Dim varname[([subscripts])][, varname[([subscripts])]] . . .

Arguments:

  • varname: Name of the variable; follows standard variable naming conventions.

  • subscripts: Dimensions of an array variable. The subscripts argument uses the following syntax:

    upperbound [,upperbound] . . . The lower bound of an array is always zero.

Remarks

Variables declared with Dim at the script level are available to all procedures within the script. At the procedure level, variables are available only within the procedure.

You can also use the Dim 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 in 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.

Note:

When you use the Dim statement in a procedure, you generally put the Dim statement at the beginning of the procedure.

The following examples illustrate the use of the Dim statement:

Example 1:


Dim Names(9)       ' Declare an array with 10 elements.
Dim MyVar, MyNum   ' Declare two variables.
	
Dim MyVariable
Dim MyVar1, MyVar2, MyVar3	
Dim MyArray(5) ' Creates an array with 6 elements (0 to 5)
	
Dim MyDynamicArray()
ReDim MyDynamicArray(10) ' Now it has 11 elements (0 to 10)
	
Dim count 
count = 10
Dim MyArray 
MyArray = Array("a1", "a2")

Dim Check, Counter
Check = True: Counter =0 'Initialize variables