Microsoft KB Archive/189735

= BUG: Removing Collection Elements Takes Longer Than Expected =

Article ID: 189735

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q189735



SYMPTOMS
In Visual Basic 6.0, removing elements from the end of a collection takes longer than removing elements from the beginning.



CAUSE
When removing an element from a collection, Visual Basic 6.0 begins at the beginning of the collection and traverses the collection until the desired element is reached, then that element is removed.



RESOLUTION
Remove elements from the beginning of the collection rather than the end.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Form1 is created by default. Select Add Module from the Project menu. This will create Module1. Select Project1 Properties from the Project menu. Change the Startup Object to Sub Main.  Copy and paste the following code into Module1: Sub Main

Dim c As New Collection Dim a As Long

Set c = New Collection

'Add elements to collection For a = 1 To 10000 c.Add "Thank you sir, may I have another." Next a        MsgBox "Done adding elements"

'Remove elements from end, this takes long time For a = 10000 To 1 Step -1 c.Remove a        Next a         MsgBox "Done removing elements from end"

'Add elements to collection again For a = 1 To 10000 c.Add "Thank you sir, may I have another." Next a        MsgBox "Done adding elements"

'Remove elements from beginning, this is much quicker For a = 1 To 10000 c.Remove 1 Next a        MsgBox "Done removing elements from end" End Sub  Press the F5 key to run the project. Note the time difference between the two methods of deleting elements from a collection.</li></ol>

Additional query words: kbDSupport kbVBp600bug kbVBp kbdss kbNoKeyWord

Keywords: kbbug KB189735

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.