473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Looping through tw-dimensional array

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

Nov 30 '06 #1
2 6976


<ne*********@gmail.comwrote in message
news:11*********************@j44g2000cwa.googlegro ups.com...
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 "<brmyArray(" & i & "," & j & ") = " & myArray(i,j)
Next
Next
Dec 1 '06 #2
Cheers!

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

Thanks a bunch!

Liam

McKirahan wrote:
<ne*********@gmail.comwrote in message
news:11*********************@j44g2000cwa.googlegro ups.com...
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 "<brmyArray(" & i & "," & j & ") = " & myArray(i,j)
Next
Next
Dec 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per...
2
by: Ivo | last post by:
Hi, I have an audio file (.mid or .wav or .mp3) in an object element: <object id="snd" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"...
45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
5
by: masood.iqbal | last post by:
My simplistic mind tells me that having local variables within looping constructs is a bad idea. The reason is that these variables are created during the beginning of an iteration and deleted at...
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
0
by: alexsink | last post by:
I am trying to get apache content negotiation to redirect only zh-CN(mainland China, where Simplified Chinese translations are available) language types to Chinese web pages, and have all other...
0
by: anthon | last post by:
Hi all - first post! anywho; I need to create a function for speeding up and down a looping clip. imagine a rotating object, triggered by an action, and slowly decreasing in speed, till it...
2
by: Justin | last post by:
Is there a way to get the ddl for a subset of tables? In this case, get all the tables beginning with emp from the sample db? Example db2look -e -tw emp* -d sample
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
2
by: Davaa | last post by:
Dear all, I am a student making a MS Form application in C++. I would ask a question about "Timer". Sample code which I am developing is below. private: System::Void...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.