O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Array Function

Syntax

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

Use: Optional

Data Type: Any

The data to be assigned to the first array element.

elementN

Use: Optional

Data Type: 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 similar 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 data type, including objects, to the Array function. You can also pass the values returned by calls to other Array functions to create multidimensional arrays; these kinds of arrays are called “ragged” arrays.

Rules at a Glance

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

  • 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 function.

  • If you don’t pass any arguments to the Array function, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required