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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2-Dimensional Array Problem with QuickSort

Status
Not open for further replies.

Gaby10414

Programmer
Jan 10, 2005
3
US
Hello,

I am using a 2-dimensional array to retrieve results from my database and display them. Each record has 6 values and I place them into the array one after the other using the For loop script below. Once all of the records are stored in the ARRAY they will be ordered using QuickSort and then displayed. The order of each record depends on a number that is returned for each record from the database.

Dim problemArray(100,2)

For i=0 to UBound(dataArray)-6 Step 6
problemArray(i,0) = dataArray(i)
problemArray(i,1) = dataArray(i+4)
Next

Call QuickSort(problemArray)
' At this point we use a FOR loop to retrieve the ordered values from QuickSort and display them.

THE PROBLEM:

The problem is the way we declare the problemArray. If 'problemArray' has a too low first dimension, an ASP error will be received in the moment of the loop AFTER THE QUICKSORT (Display Results loop). If we assign a higher number to that dimension (from my tests higher with 100), the QuickSort function will return an "OUT OF STACK" error. This is a recursive function.

How can we create the problemArray without being forced to assign a specific number (at least for the first dimension). ReDim isn't the option. Something that in the case of the single dimension arrays we achieve by using Split function for a string.

Standard SQL ordering is not an option as all ordering of database results is accomplished using ASP script and a RANK number returned with every record by the database.

Any adice would be appreciated.

Jeff

 
Hello Gaby10414,

I am not fully understand the problem of the effect on the sorting etc etc. But, I think you may be erroneous when you prepare the problemarray.
Code:
Dim problemArray() 
ReDim problemArray(ubound(dataArray)\6,2)

For i=0 to UBound(dataArray)-6 Step 6 
problemArray(i mod 6,0) = dataArray(i)
problemArray(i mod 6,1) = dataArray(i+4) 
Next
regards - tsuji
 
Correction:

Sorry, I meant this.
[tt]
problemArray(i[red]\6[/red],0) = dataArray(i)
problemArray(i[red]\6[/red],1) = dataArray(i+4)
[/tt]
- tsuji
 
BTW, the quicksort error probably occurs around 129 to 130 if I remember correctly.

See your other post for a possible direction.

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top