Multi-dimensional Arrays
Think of multi-dimensional arrays in terms of a table holding
columns and rows. To create a multi-dimensional array simply specify
the number of columns and rows you want the array to have.
For example myArray(2,3) would have 3 columns and 4 rows.
The table below could represent our multidemsional array 'myArray(2,3)'.
Each cell holds a value. Below cell (0,3) holds a "bmw".
| |
0 |
1 |
2 |
| 0 |
toyota |
white |
22.000 |
| 1 |
ford |
blue |
12.500 |
| 2 |
porshe |
red |
50.000 |
| 3 |
bmw |
yellow |
26.000 |
Below is what a multidimensional array would look like that held
the values in the table above;
<%
Dim myArray(2,3)
myArray(0,0) = "toyota"
myArray(1,0) = "white"
myArray(2,0) = "22.000"
myArray(0,1) = "ford"
myArray(1,1) = "blue"
myArray(2,1) = "12.500"
myArray(0,2) = "porshe"
myArray(1,2) = "red"
myArray(2,2) = "50.000"
myArray(0,3) = "bmw"
myArray(1,3) = "yellow"
myArray(2,3) = "26.000"
%>
Using our array 'myArray(2,3)' that we created
above we could create a HTML table and display the array values
with the code snippet below;
<%
Response.Write "<table border='0'>"
Response.Write "<tr><td>Row</td><td>Car</td>"
Response.Write "<td>Color</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 code displays the following result:
Row Car Color Cost
0 toyota white
22.000
1 ford blue 12.500
2 porshe red
50.000
3 bmw yellow
26.000
In Part 1 read about 'Arrays'
In Part 2 read about 'Array
Functions'
In part 4 read about 'Dynamic
Arrays'
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|