Message 1 of 10
How to sort a collection?

Not applicable
06-21-2002
09:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
This basic code works for arrays but I'm trying to modify it to work with
collection, any ideas what I'm doing wrong, can you not do
collection.item(i) = value?
'this code adapted from one of the many websites or ng posts, don't remember
which...
Public Sub ShellSortStringCollection(colStr As Collection)
Dim gappos As Integer
Dim swapped As Boolean
Dim tmp As Long
Dim tmpstr As String
gappos = colStr.Count \ 2
Do While gappos <> 0
Do
swapped = False
For tmp = 1 To colStr.Count - gappos
If (StrComp(colStr.Item(tmp + gappos), colStr.Item(tmp), vbTextCompare)
= -1) Then
tmpstr = colStr.Item(tmp + gappos)
'*********** here I get the error "Object required" ??? *****************
colStr.Item(tmp + gappos) = colStr.Item(tmp)
'***************************************************************************
*******
colStr.Item(tmp) = tmpstr
swapped = True
End If
Next tmp
Loop Until Not swapped
gappos = gappos \ 2
Loop
End Sub
I'm using 1 as the lbound of the collection, it seemed to bomb with 0 based.
Cant remember for sure But I think maybe collections are 1 based where
arrays are 0 based???
add watch on both of the sides of the experession show valid string data.
colStr.Item(tmp + gappos) = "some string"
colStr.Item(tmp) = "some other string"
so I dont' know what it means that it needs an object?
Any ideas?
Thanks
Mark
This basic code works for arrays but I'm trying to modify it to work with
collection, any ideas what I'm doing wrong, can you not do
collection.item(i) = value?
'this code adapted from one of the many websites or ng posts, don't remember
which...
Public Sub ShellSortStringCollection(colStr As Collection)
Dim gappos As Integer
Dim swapped As Boolean
Dim tmp As Long
Dim tmpstr As String
gappos = colStr.Count \ 2
Do While gappos <> 0
Do
swapped = False
For tmp = 1 To colStr.Count - gappos
If (StrComp(colStr.Item(tmp + gappos), colStr.Item(tmp), vbTextCompare)
= -1) Then
tmpstr = colStr.Item(tmp + gappos)
'*********** here I get the error "Object required" ??? *****************
colStr.Item(tmp + gappos) = colStr.Item(tmp)
'***************************************************************************
*******
colStr.Item(tmp) = tmpstr
swapped = True
End If
Next tmp
Loop Until Not swapped
gappos = gappos \ 2
Loop
End Sub
I'm using 1 as the lbound of the collection, it seemed to bomb with 0 based.
Cant remember for sure But I think maybe collections are 1 based where
arrays are 0 based???
add watch on both of the sides of the experession show valid string data.
colStr.Item(tmp + gappos) = "some string"
colStr.Item(tmp) = "some other string"
so I dont' know what it means that it needs an object?
Any ideas?
Thanks
Mark