Dim

This statement declares variables and allocates storage space.

Syntax

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

Parameters

varname
Name of the variable; follows standard variable naming conventions.
subscripts
Dimensions of an array variable; up to 60 multiple dimensions can be declared. The subscripts parameter uses the following syntax:
upperbound [,upperbound] . . . 

The lower bound of an array is always 0.

Remarks

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

You also can 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. An error occurs if you try to redeclare a dimension for an array variable whose size is explicitly specified in a Dim statement.

Visual Basic for Windows CE initializes numeric variables to 0 and string variables to a zero-length string (""). When you use the Dim statement in a procedure, you must put the Dim statement at the beginning of the procedure.