To create a static (non-resizable) array with 10 slots use
Dim arr(9)
To create a dynamic (resizable) array with 10 slots use
ReDim arr(9)
In each case the argument is the upper boundary of the array. Since VBScript arrays are zero-based (indexes start with 0) that is the number of elements minus one.
If you want to append to an array without knowing the required size beforehand create it as an empty dynamic array:
ReDim arr(-1)
For appending to that array you need to increase its size first:
ReDim Preserve arr(UBound(arr)+1)
arr(UBound(arr)) = "a"
ReDim Preserve arr(UBound(arr)+1)
arr(UBound(arr)) = "b"
...
You could wrap this in a procedure to simplify the handling a little:
Sub AppendToArray(ByRef a, v)
ReDim Preserve a(UBound(a)+1)
a(UBound(a)) = v
End Sub
AppendToArray arr, "a"
AppendToArray arr, "b"
...
Beware, though, that resizing an array while preserving its content is a slow operation, because VBScript creates a new array with increased size, moves the content of the existing array, and then replaces the existing array with the new one.
VBScript does not support dynamically appending to an array otherwise. As an alternative you could use the System.Collections.ArrayList
class, which does support dynamic resizing:
Set arr = CreateObject("System.Collections.ArrayList")
arr.Add "a"
arr.Add "b"
...