What is the best way to iterate through an array in Classic Asp VBScript?


For i = LBound(arr) To UBound(arr)

The best way?

What is the point in asking for LBound? Surely that is always 0 isn't it?

Probably it comes from VB6. Because with Option Base statement in VB6, you can alter the lower bound of arrays like this:

Option Base 1

Also in VB6, you can alter the lower bound of a specific array like this:

Dim myArray(4 To 42) As String

Why not use For Each? That way you don't need to care what the LBound and UBound are.

Dim x, y, z
x = Array(1, 2, 3)

For Each y In x
    z = DoSomethingWith(y)
Chris Farmer

Option Base doesn't seem to work in ASP

Yes it only does in VB6 like I said. My point is that this usage comes from VB6 programmers who are also ASP (VBScript) programmers.