Name

Array Function

Syntax

Array([element1], [elementN],....)
element

Use: Required

Data Subtype: Any

The data to be assigned to the first array element.

elementN

Use: Optional

Data Subtype: Any

Any number of data items you wish to add to the array.

Return Value

A variant array consisting of the arguments passed into the function.

Description

Returns a variant array containing the elements whose values are passed to the function as arguments.

The code fragment:

Dim vaMyArray
vaMyArray = Array("Mr", "Mrs", "Miss", "Ms")

is equivalent to writing:

Dim vaMyArray(3)
vaMyArray(0) = "Mr"
vaMyArray(1) = "Mrs"
vaMyArray(2) = "Miss"
vaMyArray(3) = "Ms"

Because Array creates a variant array, you can pass any datatype, including objects, to the Array function. You can also pass the values returned by calls to other Array functions to create multidimensional arrays (but see the comment on multidimensional arrays in the “Programming Tips & Gotchas” section).

Rules at a Glance

  • Although the array you create with the Array function is a variant array datatype, the individual elements of the array can be a mixture of different data subtypes.

  • The initial size of the array you create is the number of arguments you place in the argument list and pass to the Array function.

  • The lower bound of the array created by the Array function is 0.

  • The array returned by the Array function is a dynamic rather than a static array. Once created, you can redimension the array using Redim, Redim Preserve, or another call to the Array ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.