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

Sort Multi Array 3

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
US
I have the standard Multi Array that need to get sorted, now before you google read my post

sample array:
Code:
1     8      Text   ..... to 9 columns
3     12     Text
2     24     Text
4     5      Text
6     1      Text
5     21     Text

All of the arrays samples i can find sort the elements within each row and leave the rows themselves untouched. I need to find one that won't change the order of the row elements, but will only change the order of the rows.

Want it:
Code:
1     8      Text
2     24     Text
3     12     Text
4     5      Text
5     21     Text
6     1      Text

If this were asp.net it would be easier, but it's just classic asp. Anyone have an example they can share?

 
So the diministion are reversed. The first row should be the rows and the second is the columns.
 
Your loop outputs an error, that's why I had to change it:" - granted (and oops!), but you changed it more than just adding response write; you changed which dimension it was looping on.

Does the output make sense? The problem is how you are building your input array. I suspect when you declare the array you've swapped the dimensions.

It should be DIM(columns,rows) but likely you have DIM(rows,columns) or something like that.

Post your array code and we'll see what it looks like.
 
Oh, i see what you mean(yes finally)

Code:
width: 9
height: 0
this is row 0 | 2|8|am|11|am|Blank|Advanced Composite Veneers (must attend a.m. lecture)|West Building|105|168

This is the end of my array. There are 10 columns and 1 rows.
HERE --: 2
error '80020009'

That output looks much better! I was reading it in and switching just like you thought. Can't believe i did that!

Still having problems with the recordset.
Code:
...
...    IF isArray(input_array) THEN
        FOR i = 0 TO UBOUND(input_array,2) -1
            rs.AddNew
            rs("col_01")    = input_array(0,i)
            rs("col_02")    = input_array(1,i)
            rs("col_03")    = input_array(2,i)
            rs("col_04")    = input_array(3,i)
            rs("col_05")    = input_array(4,i)
            rs("col_06")    = input_array(5,i)
            rs("col_07")    = input_array(6,i)
            rs("col_08")    = input_array(7,i)
            rs("col_09")    = input_array(8,i)
            rs.Update
        NEXT
    END IF
    
    response.write "<br>HERE --: " & input_array(0,i) &"<br>"
    response.write "<br>HERE --: " & rs("col_01")
    
    rs.Sort = "col_01 ASC"
    'rs.Sort = "col_01 DESC"
    If rs.EOF Then rs.movefirst
    SortTheResourceArray = rs.GetRows()
    rs.close
    SET rs = Nothing
 
Hmm...might be because there is only one row. Take the -1 out of the loop and see what happens. I've never been able to figure out why .addnew adds an extra line at the top.

Also, you have 10 columns, so you have to add a column in the recordset. You only have 9 (0-8) in there. Add to .append and rs("col_10")
 
BINGO!

Man this was long, if I could give you 10 starts i would. Thank you sooooo much.


The Final Code is anyone needs it

Call
Code:
SortArray = SortTheResourceArray(Course_Array)


Code:
FUNCTION SortTheResourceArray(input_array)   
    dim rs
    set rs=createobject("adodb.recordset")
    With rs.Fields
        .Append "col_01",adInteger
        .Append "col_02",adVarChar, 255 'adInteger
        .Append "col_03",adVarChar, 255 'adInteger
        .Append "col_04",adVarChar, 255 'adInteger
        .Append "col_05",adVarChar, 255 'adInteger
        .Append "col_06",adVarChar, 255 'adInteger
        .Append "col_07",adVarChar, 65534 'adInteger
        .Append "col_08",adVarChar, 255 'adInteger
        .Append "col_09",adVarChar, 255 'adInteger
        .Append "col_10",adInteger
    End With
    rs.Open
    IF isArray(input_array) THEN
        FOR i = 0 TO UBOUND(input_array,2)
            rs.AddNew
            rs("col_01")    = input_array(0,i)
            rs("col_02")    = input_array(1,i)
            rs("col_03")    = input_array(2,i)
            rs("col_04")    = input_array(3,i)
            rs("col_05")    = input_array(4,i)
            rs("col_06")    = input_array(5,i)
            rs("col_07")    = input_array(6,i)
            rs("col_08")    = input_array(7,i)
            rs("col_09")    = input_array(8,i)
            rs("col_10")    = input_array(9,i)
            rs.Update
        NEXT
    END IF
    
    rs.Sort = "col_01 ASC"
    If rs.EOF Then rs.movefirst
    SortTheResourceArray = rs.GetRows()
    rs.close
    SET rs = Nothing   
END FUNCTION

Output
Code:
For x=0 to ubound(SortArray,2)
...
...
 
TheCandyman - if you get a row of zeroes as the first record in your array, use FROM 1 to UBOUND(SortArray,2). It's an artifact from the recordset - I have yet to figure that one out. Other than that, go nuts.

Thanks Monksnake. Everyone's usually patient enough with me. Sheco was on top of it too.
 
travis,
you truly are patient. you stuck with me through 32 posts and helped me and you have done it again for the candyman.

~E
 
Oh, stop; you're making me blush. You probably say that to all the boys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top