?
Solved

Erasing Collection

Posted on 2000-04-18
9
Medium Priority
?
202 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:
Brendt Hess earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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:Brendt Hess
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:Brendt Hess
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:Brendt Hess
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

764 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