|
There
are a number of ways you can display the contents of a single-dimension
array. Use a 'For ... Next' loop to iterate through each element
in the array. You can find the lower and upper bounds of an array
by using the LBound and UBound functions, respectively.
The
following snippet of code displays each element of the array aFoo using
a 'For ... Next' loop
'Create
the aFoo array
Dim aFoo
aFoo = Array("Hello", "Aplus!", "How ", "are ", "you?"
Dim
iLoop
For iLoop = LBound(aFoo) to UBound(aFoo)
Response.Write aFoo(iLoop) & "<BR>"
Next
The
above code will produce the following output (when viewed through
a browser)
Hello
Aplus!
How
are
you?
There is another way to display the contents of a single-dimension
array. VBScript provides a join function that converts
the contents of an array into a string using a specified delimiter
between each element of the array in the string. To display each
element of an array, followed by a <BR>, use the following
code:
'Create
the aFoo array
Dim aFoo
aFoo = Array("Hello", "Aplus!", "How ", "are ", "you?"
Response.Write
join(aFoo, "<BR>")
This
code will produce the exact same output as the code snippet we
first examined, but it requires less code.
|