Solved

Erasing Collection

Posted on 2000-04-18
9
167 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
 
LVL 1

Author Comment

by:adam8
ID: 2728698
it is very important that the entire contents of the collection is deleted.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 27

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now