Sometimes you want to fill the content of the array
when you define the array variable. This process is to initialize the
value of the array. You can assign the value one by one or if you are
using variant type of array, you can use
to assign several values.
Dim MyNumber(1 to 3) as Integer
Dim MyWeek, MyDay
MyNumber (1) = 67 assign the value one by one
MyNumber (2) = 43
MyNumber (3) = 24
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
MyDay = MyWeek(1) ' MyDay contains "Tue".
MyDay = MyWeek(3) ' MyDay contains "Thu".
The default value of index in an array is start at 0. (You can change
the base to 1 using
, but I do not recommend
it). I recommend you specify the lower bound and upper bound of an array
explicitly to avoid confusion later. For
once you declare the size of an array, the content of each variable
inside an array is empty. For numeric type (single, double, Integer,
Long) it is automatically initialized as zero. For string type, it will
have initial values of