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

Sorting on multidimensional array

Status
Not open for further replies.

guestAsh

Technical User
Feb 27, 2004
65
GB
I have an MultiDimensional Array, and i need to sort on one part of it, how do i do this???

i've heard you can create a recordset (without connecting to a DB) and sort on it that way, is this the best way and and if so how would i do this??

thank
 
check my previous post
Code:
function SortAlpha(ary, direction, indexnum)
    Dim StopWork
    Dim i
    Dim i2
    Dim firstval()
    Dim secondval()
    
    redim firstval(ubound(ary,1))
    redim secondval(ubound(ary,1))
        
    StopWork=False
    Do Until StopWork=True
        StopWork=True
        For i = 0 To UBound(ary,2)
            if i=UBound(ary,2) Then Exit For
            if UCase(Direction) = "DESC" Then
                if isdate(ary(indexnum,i)) then compare = datediff("s",ary(indexnum,i),now()) < datediff("s",ary(indexnum,i+1),now()) else compare = ary(indexnum,i) < ary(indexnum,i+1)
                if compare Then
                    For i2 = 0 To ubound(firstval)
                        firstval(i2) = ary(i2,i)
                        secondval(i2) = ary(i2,i+1)
                        ary(i2,i) = secondval(i2)
                        ary(i2,i+1) = firstval(i2)                                    
                    Next
                    StopWork=False
                End if
            Else
                if isdate(ary(indexnum,i)) then compare = datediff("s",ary(indexnum,i),now()) > datediff("s",ary(indexnum,i+1),now()) else compare = ary(indexnum,i) > ary(indexnum,i+1)
                if compare then
                    For i2 = 0 To ubound(firstval)
                        firstval(i2) = ary(i2,i)
                        secondval(i2) = ary(i2,i+1)
                        ary(i2,i) = secondval(i2)
                        ary(i2, i+1) = firstval(i2)                    
                    Next
                    StopWork=False
                End if
            End if
        Next
    Loop
    SortAlpha=ary
End function
call it like Arraytosort= SortAlpha(Arraytosort,"ASC",DimensionToSortOn)

}...the bane of my life!
 
thanks for your help... i'll have a look.
 
Hi,

HELP! slightly confused, so how do i the write my "sorted" Arrays to the browser? i.e if i have say 30 dynamically arrays and i want them to be displayed in a table in Asc order?

thanks
 
Code:
<%
for n = 0 to ubound(sortedarray,2)
   response.write(sortedarray(0,n)&" "&sortedarray(1,n)&" "&sortedarray(2,n)&"<br />")
next%>
that should just display the contents

}...the bane of my life!
 
Thats great you made my week! works a dream. thanks very much for your time, Have a good weekend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top