
col.Remove and col.Add won't work back-to-back
What's the error? The code below should work fine with VB6/SP5
'==========
Private Sub Command1_Click()
Dim kColl As Collection
Dim i As Integer
Set kColl = New Collection
For i = 1 To 50
kColl.Add "Item " & i, "Key" & i
Next
kColl.Remove "Key12"
kColl.Add "Item 51", "Key51"
For i = 1 To kColl.Count
Debug.Print i, kColl(i)
Next
End Sub
'==========
--
Ken Halter - MS-MVP-VB - Please keep it in the groups..
http://www.vbsight.com/ - http://www.vbsight.com/MultiColumn.htm
http://www.vbsight.com/TBGDialogCTL.htm
Quote:
> If I try to remove an item from a collection and immediately add
> another:
> col.Remove anItem
> col.Add anotherItem, Key
> It causes an error. However, if I put something in between, like
> col.Remove anItem
> MsgBox "Hi"
> col.Add anotherItem, Key
> IT RUNS !! ??
> Is it the speed at which collection items are removed and added that
> causes the problem ? What can I do to correct this ??