Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse MultiDimensional Array? 3

Status
Not open for further replies.

sn0rg

IS-IT--Management
Aug 5, 2005
95
GB
Having just about grasped MD arrays I now have the following problem.

Previously, I would build an array (eg arrCars), and then pass through it with a "for each, next" loop.

eg:
Code:
Dim arrCars(1)
arrCars(0) = "Ford"
arrCars(1) = "Vauxhall"

For each objcar in arrCars
   wscript.echo objCar
Next

How do I do the same thing in a MD array, and how do I refer to the element I want?

here's the aircode:

Code:
Dim arrCars(1,1)
arrCars(0,0) = "Ford"
arrCars(0,1) = "Blue"
arrCars(1,0) = "Vauxhall"
arrCars(1,1) = "Green"

For each entry in the array arrCars
   wscript.echo Each Car and its Colour
Next
 
Well, you have to use an index. So for your example:

Dim arrCars(1,1)
arrCars(0,0) = "Ford"
arrCars(0,1) = "Blue"
arrCars(1,0) = "Vauxhall"
arrCars(1,1) = "Green"

For i = 0 To UBound(arrCars)
WScript.Echo arrCars(i,0) & " = " & arrCars(i, 1)
Next


I would also look at using a dictionary instead of a multi-dimensional array.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top