Go to: Articles List
Part 1 | Part 2 | Part 3 | Part 4
To create a multi-dimension array simply specify the number of columns
and rows you want the array to have.
myArray(2,3) would have 2 columns and 3 rows, this would basically be
like a regular array that has 3 (0-3) elements, but with 2 elements for
each row.
myArray(2,3) would physically look like this:
(with the text in the cells representing the ordinal location)
0,0 |
1,0 |
2,0 |
0,1 |
1,1 |
2,1 |
0,2 |
1,2 |
2,2 |
0,3 |
1,3 |
2,3 |
And here is some ASP code that demonstrates the use of a
multi-dimensional array:
Dim myArray(2,3)
'myArray(col,row)
'Array def is (dept,item,cost)
myArray(0,0) = "housewares"
myArray(1,0) = "sauce pan"
myArray(2,0) = "22.50"
myArray(0,1) = "housewares"
myArray(1,1) = "toaster"
myArray(2,1) = "12.50"
myArray(0,2) = "housewares"
myArray(1,2) = "wooden spoon"
myArray(2,2) = "4.50"
myArray(0,3) = "housewares"
myArray(1,3) = "oven cleaner"
myArray(2,3) = "2.50"
Response.Write("<table border=2>")
Response.Write("<tr><td>Row</td><td>Department</td>")
Response.Write("<td>Item Name</td><td>Cost</td></tr>")
For i = 0 to UBound(myArray, 2)
Response.Write("<tr><td>#" & i & "</td>")
Response.Write("<td>" & myArray(0,i) & "</td>")
Response.Write("<td>" & myArray(1,i) & "</td>")
Response.Write("<td>" & myArray(2,i) & "</td></tr>")
Next
Response.Write("</table>")
The above yields the following result:
Row | Department | Item Name | Cost |
#0 | housewares | sauce pan | 22.50 |
#1 | housewares | toaster | 12.50 |
#2 | housewares | wooden spoon | 4.50 |
#3 | housewares | oven cleaner | 2.50 |
|
|
|
|