This section provides an introduction and examples on how to declare array variables with fixed sizes or dynamic sizes.
VBScript supports 2 ways to declare an array variable:
1. Explicit Declaration with Fixed Size - Using "Dim" statement with size included as:
Dim array_name(upper_bound)
where "upper_bound" is positive integer specifying the upper bound of the element index.
Array declared in this way has a fixed size (number of elements).
By default, the size of an array is the upper bound plus 1, because index starts from 0.
This size can not be changed.
2. Explicit Declaration with Dynamic Size - Using "Dim" and "ReDim" statements as shown
in the following syntax:
Dim array_name()
...
ReDim [Preserve] variable_name(upper_bound)
...
The "Dim" statement declares an array variable without any upper bound. The "ReDim" statement resets
the upper bound to a new value. The optional key word "Preserve" specifies that all old elements
must be preserved when resetting the array size. Array declared in this way can be resized at any time.
VBScript offers some other useful functions and statements for you to work with arrays:
IsArray(variable_name) - Returns "True" if the specified value is an array.
UBound(array_variable) - Returns the upper bound of the specified array.
LBound(array_variable) - Returns the lower bound of the specified array.
"For Each" - Loops through all elements in an array.
"Erase" - Removes all values from an array.
See sections below for details and examples on those functions and statements.