How to loop through a two-dimensional array and alphabetize...

I would like to take arrNames(1,x) and alphabetize the entire array by x.

So its a two column array that appears like this:

Username, Full Name
jsmith, John Smith
dwilson, Don Wilson
mjohnson, Michelle Johnson

and I would like to just alphabetize by column two (FullName) so when i loop through the area from 1 to ubound the contents will be in this order:
dwilson, Don Wilson
jsmith, John Smith
mjohnson, Michelle Johnson

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this:

It uses a short JScript server code block to do the actual sorting since it is built into JScript.
For i = 0 To Ubound(MyArray,2)
    Response.write MyArray(0, i) & " " & MyArray(1, i)
Sorting an array in VBScript can be done in many ways. It depends a bit how big the array is, but I'd use the Sort method of a Recordset, and not JavaScript. You don't want to switch to JavaScript just for one function.

Function Sort2DArrayRS(ByVal aIn)
    Dim aReturn, oRS, i
    If Not IsArray(aIn) Then Exit Function
    Set oRS = Server.CreateObject("ADODB.RecordSet")
    oRS.Fields.Append  "username", 201, 255    ' adLongVarChar
    oRS.Fields.Append  "fullname", 201, 255    ' adLongVarChar
    oRS.CursorLocation = 3                 ' adUseClient
    For i = 0 To Ubound(aIn,2)
        oRS("username") = aIn(0,i)
        oRS("fullname") = aIn(1,i)
    oRS.Sort = "fullname"
    Sort2DArrayRS = oRS.GetRows()
    oRS.Close:Set oRS = Nothing
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.