Classic ASP Arrays: VBScript Examples

Last updated: August 25, 2026.

Classic ASP uses VBScript arrays to store several related values under one variable name. Array indexes start at zero, and VBScript supports both fixed-size and resizable arrays.

Create and loop through a fixed-size array

The number in parentheses is the upper bound, not the number of items. Dim cars(4) creates five positions: 0 through 4.

Dim cars(4)
cars(0) = "BMW"
cars(1) = "Mercedes"
cars(2) = "Audi"
cars(3) = "Bentley"
cars(4) = "Mini"

Dim i
For i = LBound(cars) To UBound(cars)
    Response.Write Server.HTMLEncode(cars(i)) & "<br>"
Next

Use LBound() and UBound() instead of hard-coding loop limits. The loop continues to work if the array bounds change.

Create an array with Array()

Dim cars
cars = Array("BMW", "Mercedes", "Audi", "Bentley", "Mini")

Response.Write cars(0)  ' BMW
Response.Write UBound(cars)  ' 4

Array() is convenient when all initial values are known. The result is stored in a Variant containing an array.

Resize a dynamic array

Declare an array without an upper bound, allocate it with ReDim, and use ReDim Preserve when existing values must remain:

Dim cars()
ReDim cars(1)

cars(0) = "BMW"
cars(1) = "Audi"

ReDim Preserve cars(3)
cars(2) = "Mini"
cars(3) = "Volvo"

ReDim Preserve can resize only the last dimension of a multidimensional array. For a grid or matrix, see multidimensional arrays in Classic ASP.

Clear an array

Erase cars

If IsArray(cars) Then
    Response.Write "cars is still an array"
End If

Erase releases a dynamic array’s storage and resets the elements of a fixed-size array. Use IsArray() when a Variant may or may not contain an array.

Useful VBScript array functions

  • Array() creates and fills an array.
  • LBound() returns the lowest available index.
  • UBound() returns the highest available index.
  • Split() converts a delimited string into an array.
  • Join() combines a one-dimensional array into a string.
  • Filter() returns matching values from a string array.

For the surrounding server-side page structure, see what Classic ASP code looks like.

admin

admin

Leave a Reply

Your email address will not be published.