Assigns a list of values to consecutive elements of a one-dimensional Array.


result = Array(elementList)





Any valid datatype for an array

Name of the array that is populated with the items in ElementList.


Type of result

A comma-delimited list of values that are used to populate result.



Only one-dimensional arrays are supported by Array. Higher dimensional arrays can be populated via assignment statements.

The Array function provides the same functionality as separate assignment statements for each element of an Array, beginning with element zero and proceeding consecutively. If there are more elements in the Array than items in the list of elements, then the "extra" elements are not disturbed.

All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646.

Type considerations

If the ElementList contains numeric data of different word lengths and/or a mixture of signed and unsigned integers, Array will use the lowest common data type that accommodates all the elements.

For example, because hexadecimal numbers are unsigned integers, the following code will generate a Type Mismatch Error:

Var hexNums() As Integer
hexNums = Array(&h1, &h2)

You need to be careful about word length and whether or not the integer is signed. You should instead declare the Array of type UInt64:

Var bigInts() As UInt64
bigInts = Array(&h1, &h2)

If you wish, you can also decide to convert one of the values to a signed integer. In that case, Array will return an Integer Array. Use either of the following ways:

Var numbers() As Integer
numbers = Array(Int64(&h1), &h2) // Once you convert one value type, the rest will follow

Or this:

Var numbers() As Integer
numbers = Array(1, &h2)

Sample code

The following statements initialize the Array using separate assignment statements for each Array element:

Var names(2) As String
//using separate assignment statements
names(0) = "Fred"
names(1) = "Ginger"
names(2) = "Stanley"

The following statements use the Array function to accomplish the same thing. Note that you don't have to declare the exact size of the Array in the Var statement. The Array function will add elements to the Array as needed.

The following statement creates and populates the first three elements of the Array aNames.

Var names() As String
// using the Array function
names = Array("Fred", "Ginger", "Stanley")


All project types on all supported operating systems.

See also

Arrays concept; Var, For Each...Next, ParamArray commands; Dictionary class; Collections of Data topic