O'Reilly logo

VBScript Pocket Reference by Matt Childs, Paul Lomax, Ron Petrusha

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

Chapter 2. VBScript Reference

Array Handling

Array Function

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

Type: Required, Any

The data to be assigned to the first array element.

elementN

Type: Optional, 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.

Dim Statement

Dim varname[([subscripts])],
varname[([subscripts])]
varname

Type: Required

Your chosen name for the variable.

subscripts

Type: Optional

Dimensions of an array variable.

Description

Declares and allocates storage space in memory for variables. When used in a procedure, the variable declared using Dim is local to that procedure. When used in a module or scripting block, it’s available throughout the module. It is recommended, but not required, that Dim statements be placed at the beginning of the code block or procedure.

Erase Statement

Erase arraylist
arraylist

Type: Required, Variant array

A list of array variables to clear.

Description

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