Sorting a Collection (1 Viewer)

doulostheou

Registered User.
Local time
Yesterday, 19:33
Joined
Feb 8, 2002
Messages
314
I know that my biggest problem is that I need to become more familiar with collections, but I wanted to post this here in case I don't get very far in educating myself.

Is there an easy way to sort a collection? I was going to try the Shell Sort method, but I am running into a few difficulties applying it to the collection. As I was tearing out what little hair I have left, it dawned on me that there may be a simple way to sort the collection that I'm not aware of.
 

doulostheou

Registered User.
Local time
Yesterday, 19:33
Joined
Feb 8, 2002
Messages
314
Thanks for the link. My biggest problem was that I wasn't properly adding or removing objects from the collection.

I've included the shell sort in case anyone who stumbles across this post is interested in using that particular sort method:

Code:
  Dim lngLoop1 As Long
  Dim lngHold As Long
  Dim lngHValue As Long
  Dim agntTemp As New Agent

  lngHValue = 1
  Do
    lngHValue = 3 * lngHValue + 1
  'objAgents is a public collection
  Loop Until lngHValue > objAgents.Count
  Do
    lngHValue = lngHValue / 3
    For lngLoop1 = lngHValue + 1 To objAgents.Count
      Set agntTemp = objAgents(lngLoop1)
      lngHold = lngLoop1
      Do While objAgents(lngHold - lngHValue).SortProperty > agntTemp.SortProperty
        objAgents.Remove lngHold
        objAgents.Add agntTemp, agntTemp.EID, lngHold - lngHValue
        lngHold = lngHold - lngHValue
        If lngHold <= lngHValue Then Exit Do
      Loop
    Next lngLoop1
  Loop Until lngHValue = 1
 

Users who are viewing this thread

Top Bottom