An array is a set of values that are logically related to each other. You refer to these values by the same variable name and use a number called an index or subscript to distinguish each individual value. These values are called the elements of the array and occupy a contiguous range from zero to a defined upper bound.

Variables other than arrays are referred to as scalars. A scalar can hold only one value at a time.

Creating an array

You create an array using the same statements you use to create scalar variables. The only difference is the addition of the size of the array, which is placed inside rounded brackets in the examples below.

Listing 1
Dim my_first_array(10)

Because my_first_array uses one index or subscript, it is called a onee-dimensional array. You also are able to create arrays with more than one subscript, commonly called multidimensional arrays. For more information, see Array Dimensions.

Storing values in an array


Populating an array with initial values

You can give an array some initial values by using an array initializer. An array initializer consists of a list of values separated by commas and enclosed inside of curly braces ({ and }).

Dim days$() = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }

Nesting initializers

You can create multidimensional arrays by nesting array initializers.

Dim magic() = {{4, 9, 2}, {3, 5, 7}, {8, 1, 6}}

Iterating through an array


Arrays as parameters


Array size


See also