<
Previous lesson
|
Table of Content
|
Content of this Chapter
|
Next lesson
>
Array Initialization
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
Array
function
to assign several values.
Example:
Dim MyNumber(1 to 3) as Integer
Dim MyWeek, MyDayMyNumber (1) = 67 assign the value one by one
MyNumber (2) = 43
MyNumber (3) = 24MyWeek = 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
Option Base
, 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
Variant
type,
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
(empty string).
<
Previous lesson
|
Table
of Content
|
Content of this Chapter
|
Next lesson
>