Using Variables And Arrays


The Array function works well when you specify a number of items to place in the array. Although all elements you add to the array are variants, you can have a mixture of different data types. For example, you can add both strings and numeric values to the same variable using the Array function.

Because you create dynamic arrays with the Array function, you can use the Redim statement to change the size of the array after you create it. You can also use the Array function again within the same procedure to reassign the values in the array. See the section "Redimension an Array" for more information on resizing an array.

The Option Base statement does not change the lower bounds for arrays you create with the Array function. All arrays have a lower bounds index value of 0. Therefore, if you add three items to the array using the Array function, the upper bounds value is 2. The following code adds three values to TestArray with the first element having an index value of 0.


TestArray = Array("One", "Two", "Three") MsgBox(TestArray(2))

The message box displays a value of Three because the first element of the array has an index value of 0.

Type MsgBox(ArrayVar(N)), replacing ArrayVar with the name of the variable and N with the index of the array element.

0 0

Post a comment