# 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:

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

Thanks!
Matt
LVL 1
###### 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.

Commented:
Try this: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=89

It uses a short JScript server code block to do the actual sorting since it is built into JScript.
0
Commented:
<%
For i = 0 To Ubound(MyArray,2)
Response.write MyArray(0, i) & " " & MyArray(1, i)
Next
%>
0
Commented:
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
oRS.Fields.Append  "fullname", 201, 255    ' adLongVarChar
oRS.Open
For i = 0 To Ubound(aIn,2)
oRS("fullname") = aIn(1,i)
oRS.Update
Next
oRS.Sort = "fullname"
Sort2DArrayRS = oRS.GetRows()
oRS.Close:Set oRS = Nothing
End Function
0

Experts Exchange Solution brought to you by

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

###### 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
ASP

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.