dim
Create an array or variable named name . Arrays can have up to 5 indexes, and are initialized to zeros. Variables can optionally be assigned by Dim statements.
Syntax
dim {Common|Shared} name []
dim {Common|Shared} name = expression
dim {Common|Shared} name [ maxValue {,...} ]
dim {Common|Shared} name [ minValue To maxValue {,...} ]
Common declares variables and arrays as global. These do not need to be declared as Shared when used in a Sub or Function . Common can only be used outside of Sub and Function .
Shared declares variables and arrays defined outside the routine that has not been declared as Common . Shared can only be used inside a Sub or Function .
You can write multiple variable and array declaration by separating them by commas.
Example:
dim a[1] , b[3,5] , counter , x , y
If no indexes are specified, a dynamic array will be created. Indexes can be any value ( numeric or strings ) but they will be stored internally as strings. For example:
a[1] = "one"
and
a["1"] = "one"
are identical. You can have as many indexes as you wish, but the result is simply combined into a single string. For example:
a["this",22] = "some value"
is the same as writing:
a["this,22"] = "some value"
If you request an index from a dynamic array that has not been assigned, it will return an empty string "".
Dynamic arrays also differ from static arrays in that that elements can only be passed by value, not by reference.
Example:
' Create an array
dim a[3 To 10, 5]
' Create a variable and assign it
dim myVar = 100
Example:
dim array$[100]
for i = 0 to 100
array$[i]="record"+str$(i)
next
for i = 0 to 100
print(array$[i])
next
dim array$[10 to 110]
for i = 10 to 110
array$[i]="record"+str$(110-i)
next
for i = 10 to 110
print(array$[i])
next
See also erase command.