Looping through tw-dimensional array

N

neptune6644

I need to loop through a two-dimesnional array (x,y) until a value in x
is empty or the end of the array is reached, whichever comes first.

Example array:

Dim myArray(4,1)

myArray(0,0) = "part 1"
myArray(0,1) = quantity
myArray(1,0) = "part 2"
myArray(1,1) = quantity
myArray(2,0) = "part 3"
myArray(2,1) = quantity
myArray(3,0) = ""
myArray(3,1) = quantity
myArray(4,0) = "part 5"
myArray(4,1) = quantity


In the example above, the loop should stop once it determines
myArray(3,0) is empty. If myArray(3,0) was not empty, the loop would
continue until the end of the array was reached.

Anybody have a code example to do this?

Thanks,

Liam
 
M

McKirahan

I need to loop through a two-dimesnional array (x,y) until a value in x
is empty or the end of the array is reached, whichever comes first.

Example array:

Dim myArray(4,1)

myArray(0,0) = "part 1"
myArray(0,1) = quantity
myArray(1,0) = "part 2"
myArray(1,1) = quantity
myArray(2,0) = "part 3"
myArray(2,1) = quantity
myArray(3,0) = ""
myArray(3,1) = quantity
myArray(4,0) = "part 5"
myArray(4,1) = quantity


In the example above, the loop should stop once it determines
myArray(3,0) is empty. If myArray(3,0) was not empty, the loop would
continue until the end of the array was reached.

Anybody have a code example to do this?

Will this help?

Option Explicit
Dim myArray(4,1)
myArray(0,0) = "part 1"
myArray(0,1) = 1
myArray(1,0) = "part 2"
myArray(1,1) = 2
myArray(2,0) = "part 3"
myArray(2,1) = 3
myArray(3,0) = ""
myArray(3,1) = 4
myArray(4,0) = "part 5"
myArray(4,1) = 5
Dim i, j
For i = 0 To UBound(myArray,1)
If myArray(i,0) = "" Then Exit For
For j = 0 To UBound(myArray,2)
Response.Write "<br> myArray(" & i & "," & j & ") = " & myArray(i,j)
Next
Next
 
N

neptune6644

Cheers!

Looks like you're responsible for me actually getting some sleep
tonight!!

Thanks a bunch!

Liam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top