Solved

Erasing Collection

Posted on 2000-04-18
9
197 Views
Last Modified: 2010-05-02
Hi,
I want to erase the contents of a collection but this doesn't work, just say TheCollection already stored 23 entrees

For X = 1 To TheCollection.Count
    TheCollection.Delete(X)
Next X

Can someone give me code that would work
0
Comment
Question by:adam8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 2728658
Don't remove them using X as the item to remove.  Instead, just remove the first item in the collection each time (there will always be a first item)

Also, shouldn't this be .Remove, not .Delete?

For X = 1 to TheCollection.Count
  TheCollection.Remove 1
Next X
0
 
LVL 1

Author Comment

by:adam8
ID: 2728686
sorry,
it is delete, i just got mixed up.
The problem is that i store info to the collection until the user changes his/her selection, then if that happens i need to remove every item in the collection and then add different info to the collection the second time.
Get it, i need to remove all the items in the collection, not just the first one.
0
 
LVL 1

Author Comment

by:adam8
ID: 2728693
I think it is delete,
It doesn't matter anyway,
I know what you are talking about
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Author Comment

by:adam8
ID: 2728698
it is very important that the entire contents of the collection is deleted.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2728704
The .Delete versus .Remove doesn't matter - it could be version differences.   Just go with removing the first entry each time in your for...next loop, and you'll be fine.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2728711
The reason this will work:

Assume you have five items in your collection.  When you delete the first item, the 2nd item is automatically renumbered to be the first item, the 3rd becomes the 2nd, etc.

Given a collection:

1  2  3  4  5
After deleting #1, your collection is:

1  2  3  4
After deleting #2, your collection is:

1  2  3

Etc.
0
 
LVL 1

Author Comment

by:adam8
ID: 2728745
ok, i forgot to think about that.
so how would i go about deleting these items.

For X = 1 to Items.Count
    Items.Delete(1)
Next X

Would that work?
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2728771
That should be just perfect.
0
 
LVL 28

Expert Comment

by:Ark
ID: 2728828
Hi
For collection it's better to use For Each statement:
Dim X As Variant, TheCollection As Collection
For Each X in TheCollection
    TheCollection.Remove (1)
Next X
BTW, if your collection has delete method, may be it has clear method?
Cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question