Vbscript Array For Loop
Vbscript for loop enables you to loop though array items to get the value of array elements at each index. Vbscript array for loop counter variable increments each time that is used to get the value of array at each index increasing towards the UBound of the array collection. Vbscript Array UBound function is used to define the vbscript for loop counter condition to start from the 0th index to UBound i.e. upper bound last topmost index of the array collection whose values is to be retrieved.
Classic ASP VbScript Array Functions Examples:
You can see the live samples and examples of Classic ASP VbScript Array Functions from the following links:
Syntax for Vbscript Array for loop
Dim counter For counter = 0 To UBound(myArray) ' vbscript Code to get array values at each index Next
Example of Vbscript Array For loop
<% Dim myArray(11) myArray(0) = "January" myArray(1) = "February" myArray(2) = "March" myArray(3) = "April" myArray(4) = "May" myArray(5) = "June" myArray(6) = "July" myArray(7) = "August" myArray(8) = "September" myArray(9) = "October" myArray(10) = "November" myArray(11) = "December" Dim counter For counter = 0 To UBound(myArray) Response.Write(myArray(counter) & "<br />") Next %>
Above example will return the names of months stored at each index of array of size 11. Array with size 11 can store 0 to 11 i.e. 12 items which is equal to number of months. UBound array function of vbscript will return 11 that will exit for loop for the counter value greater than 11.
Continue to next tutorial: ASP Vbscript Array For Each Loop to learn how to read the Array items using for each loop.