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

Get VBScript Pocket Reference 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.