VBS tutorial: VBScript statement dim statement


Dim statement

Declare variables and allocate storage space.

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



The name of the variable conforms to the standard variable naming convention.


The dimension of an array variable. You can declare an array of up to 60 dimensions.subscriptsParameters use the following syntax:

upperbound [,upperbound] . . .

The lower bound of the array is always 0.


useDimThe declared script level variables can be used in all procedures in the script, and process level variables can only be used in procedures.

Empty parentheses can also be usedDimStatement to declare a dynamic array. After a dynamic array is declared, it can be used within a procedureReDimStatement to define the dimensions and elements of the array. If you try to redefineDim Statement, an error occurs.

be carefulUse in processDimStatement, usuallyDimStatement is placed at the beginning of the procedure.

The following example illustrates how to useDimsentence:

Dim names (9) 'declares an array of 10 elements. Dim names() 'declares a dynamic array. Dim myvar, mynum 'declare two variables.