Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

zero2130 (Programmer)
2 Feb 01 15:02
How can I do this?

I have an array that I want to be sorted alphabetically.  Is there an easy way to do this or do you know of/have you written a function that'll do this?

Thanks
Guest (Visitor)
5 Feb 01 14:42
There are a few traditional algorithms ( not that Al Gore has rhythm ) for performing such a sort, such as the bubble sort, etc.  It would probably require slightly less code ( and would be a lot sexier ) to load the data into an XML Document object and then perform a select nodes with a sort applied.

Does anybody miss perl hash tables yet?

JAC
wrbodine (Programmer)
12 Dec 01 16:42
Does Jac or anyone have an example of loading the data into an XML document?  I think the sort part in XML will be easy but I've never yet loaded data from VBScript code into an XML document....

Thanx,
Ray
dilettante (MIS)
15 Dec 01 0:38
Take a look here: http://www.angelfire.com/mi4/bvo/deliveries.html

There is a nice VBScript sort all ready to include using a <script> tag.
Parke (Programmer)
20 Dec 01 16:08
Why not load the array into a disconnected recordset and sort?
wrbodine (Programmer)
20 Dec 01 16:12
We've been wanting to start using XML here, so I thought it would be a good chance to get my feet wet.  I'm using a bubble sort for now, but am intrigued by the recordset idea as well, since I've never heard of doing that....
Parke (Programmer)
21 Dec 01 8:38
Here is an example of using a recordset to sort.

option explicit

Dim myArray
Dim rst
Dim s
Dim xitem

myArray = Array("Parke Kuntz", "Jane Doe", "Mary Smith", "John Cole", "May Abbot","John Doy", "Mary Scale")

' create a recordset
Set rst = createObject("ADODB.Recordset")

' create/append the fields to the recordset
rst.Fields.Append "fullname",129,50  'AD_Char = 129 and character length is 50
rst.Fields.Append "fname",129,50
rst.Fields.Append "lname",129,50

' open the recordset
rst.Open
' insert the array into the recordset
For Each xitem in myArray
    rst.AddNew
    rst.Fields("fullname") = xitem
    ' extract the first name from fullname
    rst.Fields("fname") = Left(rst.Fields("fullname"), Instr(rst.fields("fullname")," ") -1)
    ' extract the last name from fullname
    rst.Fields("lname") = Right(rst.Fields("fullname"), (Len(rst.Fields("fullname"))-Instr(rst.Fields("fullname")," ")))
    rst.Movenext
Next

rst.moveFirst
' choose the field to sort on
rst.Sort = "lname"

s = "sorted by last name"
Do until rst.EOF
    s = s & vbcrlf & rst.Fields("fullname")
    rst.MoveNext
Loop

msgbox s

s = "sorted by first name"
rst.MoveFirst
' choose the order of the fields you want to sort on
rst.Sort = "fname, lname"
Do until rst.EOF
    s = s & vbcrlf & rst.Fields("fullname")
    rst.MoveNext
Loop

msgbox s

Hope this helps,

jbaywatch (Programmer)
24 Dec 01 0:45
Wow, not to be argumentative or disrespectful to anyone. But isn't both of those methods (XML and RS) a waste of server cycles?

I just don't understand why anyone would go to such lengths as to spawn new processes to sort an array in a production environment.

I would use the bubbleSort, XML and ADO have their places and IMHO, this isn't it.

Fo the XML method I am guessing you would have to actually create 2 instances of The MSXML parser. One for the DOM and one for the XSL transform that will actually perform the sort.

Just my 2 cents.

-J
Parke (Programmer)
24 Dec 01 9:04
If all that was wanted was a simple sort, I would agree with you.  With recordsets, one can sort on different columns by priority simply by filling in .sort = "field1, field2,field3..."  This is the second sort.  Doing this is more difficult using sorting routines.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close