VBScript » Functions » Array

Version: 2.0

Syntax:
Array(List)

The Array function is used to create a static one-dimension array. You cannot declare a dynamic array using the Array function.

Note that the first element in an array is always labeled zero, for example,
myarray(0).

The List argument is a listing of values that will become the elements of the array.

A dynamic array is declared using the Dim and the ReDim statements. First, you use the Dim statement to declare the dynamic array by using empty parenthesis. Then, at a later point in your program, you use the ReDim statement to declare the number of elements. In fact, you can re-declare a dynamic array as many times as you desire.

Examples

Code:
<% myarray = array("A", "B", "C", "D") %>
<% =myarray(0) %>
<% =myarray(1) %>
<% =myarray(2) %>
<% =myarray(3) %>
Output:
A B C D
Language(s): VBScript
Code:
<% myarray = array(111, 222, 333, 444, 555) %>
<% =myarray(0) %>
<% =myarray(1) %>
<% =myarray(2) %>
<% =myarray(3) %>
<% =myarray(4) %>
Output:
111 222 333 444 555
Language(s): VBScript
Code:
<%
Dim SomeArray()
...
ReDim SomeArray(22)
...
ReDim SomeArray(500)
%>
Language(s): VBScript
Code:
<% Dim ThreeDimensionArray(22, 14, 200) %>
Language(s): VBScript

See Also: