Solved

Erasing Collection

Posted on 2000-04-18
9
182 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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