Customer Login  .   Webmail Login  .   About Us  .   Contact Us
Go to: Articles List

Arrays How To Part 3 : Multi-dimensional arrays
[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:

RowDepartmentItem NameCost
#0housewaressauce pan22.50
#1housewarestoaster12.50
#2housewareswooden spoon4.50
#3housewaresoven cleaner2.50

Shared Hosting
Rookie
Pro
Advanced
Dedicated Servers
BASE
BUSINESS
ENTERPRISE
Why Choose Brinkster?
Radical Support
Brinkster Datacenter
Brinkster Network
Corporate Social Responsibility
90 Day Money Back Guarantee
Unsurpassed Value
Client Testimonials
Additional Features
Antivirus
Merchant Account
E-Commerce
Live Chat Communicator
Free Firewall
Website Builder
Free Web Hosting
Support
General Support
Codebank Search
Forums
Articles
Click here for Brinkster Live Chat
Home   Domains   Shared Hosting   Dedicated Hosting   Partner   Support   About Us    Contact Us   Webmail
Copyright © Brinkster Communications Corporation All Rights Reserved. Privacy Policy & Legal