col.Remove and col.Add won't work back-to-back 
Author Message
 col.Remove and col.Add won't work back-to-back

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 ??



Sat, 09 Apr 2005 18:33:50 GMT  
 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 ??



Sun, 10 Apr 2005 09:13:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to add the items in a col

2. excel sheet-need sort 2 col's and total the last by date

3. Crystal won't pull back NEW data from Oracle view

4. Back color won't change

5. MSFlexGrid's col resize event

6. Back to back Excel & Word VBA macros

7. Link back from a URL without pressing BACK button

8. Link back from a URL without pressing BACK button

9. VB6 back to back mpgs

10. Backing up a back end

11. Remove Links From "Back" Navigation

12. Rolling back to vbx's afer upgrading to ocx's

 

 
Powered by phpBB® Forum Software