Arrays

<< Click to Display Table of Contents >>

 

Arrays

In certain situations, it is convenient to set more than one value related to a single variable. To do so, users can create a variable that contains a series of values, an Array-type variable.

To explicitly declare a variable, use the Dim command. An array declaration uses parentheses containing its dimension, according to the next example.

Dim A(10)

 

Users can set data to each one of the elements of an array by using an index starting at 0 (zero) and ending at the declared size. The number of elements of an array is always the number displayed inside parentheses plus 1 (one), according to the next example.

A(0) = 256
A(1) = 324
A(2) = 100
...
A(10) = 55

 

Users can also create an array by using VBScript's Array(arglist) method. This method returns a Variant-type variable containing an array. Its values must be separated by commas, according to the next example.

A = Array(10, 20, 30)
MsgBox A(0)
MsgBox A(1)
MsgBox A(2)

Was this page useful?