Home > Archive > Visual Basic > April 2006 > Using collections for the first time. How do I clear the collection for reuse?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using collections for the first time. How do I clear the collection for reuse?
|
|
| Bookreader 2006-04-25, 6:57 pm |
| How do I clear all the items from a collection? I want to transfer
the collection's to another collection, which is working fine. Then
after transferring the collection's contents, I want to empty it for
another iteration of processing.
I tried to use a loop like I would with an array:
while x < Coll.Count
Coll.Remove x
x = x + 1
Wend
but that caused an error because count is decremented every time a
member of the collection is removed.
then I tried
while Coll.Count > 0
Coll.Remove x
Wend
but that also caused an error. I thought this would work as long as
there were items in the collection.
Or, does VB use the DELETE keyword to eliminate the instance created
by NEW like in C++?
Thanks for your help with this question.
| |
| Bookreader 2006-04-25, 6:57 pm |
| On Sun, 23 Apr 2006 16:44:26 GMT, Bookreader <Bookreader127@yahoo.com>
wrote:
>How do I clear all the items from a collection? I want to transfer
>the collection's to another collection, which is working fine. Then
>after transferring the collection's contents, I want to empty it for
>another iteration of processing.
I found a full set of replies on this question at Google.
Should have searched before asking.
Thanks.
| |
| Jan Hyde 2006-04-25, 6:57 pm |
| Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
released on Sun, 23 Apr 2006 17:08:21 GMT bearing the
following fruit:
>On Sun, 23 Apr 2006 16:44:26 GMT, Bookreader <Bookreader127@yahoo.com>
>wrote:
>
>I found a full set of replies on this question at Google.
>
>Should have searched before asking.
>
LOL, better late than never. Although since you did ask the
question it would be nice to have posted the results of your
research for the next guy who does a search and comes across
your post.
Jan Hyde (VB MVP)
--
They considered their silver anniversary a sterling event. (Jumble)
| |
| bitshifter 2006-04-25, 6:57 pm |
| On Mon, 24 Apr 2006 09:10:04 +0100, Jan Hyde
<StellaDrinker@REMOVE.ME.uboot.com> wrote:
>Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
>released on Sun, 23 Apr 2006 17:08:21 GMT bearing the
>following fruit:
>
>
>
>LOL, better late than never. Although since you did ask the
>question it would be nice to have posted the results of your
>research for the next guy who does a search and comes across
>your post.
Was it something like
Do While coll.Count >0
coll.remove 1
Loop
>Jan Hyde (VB MVP)
>
>--
>They considered their silver anniversary a sterling event. (Jumble)
>
| |
| Bookreader 2006-04-25, 6:57 pm |
| On Mon, 24 Apr 2006 09:10:04 +0100, Jan Hyde
<StellaDrinker@REMOVE.ME.uboot.com> wrote:
>Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
>released on Sun, 23 Apr 2006 17:08:21 GMT bearing the
>following fruit:
>
>
>LOL, better late than never. Although since you did ask the
>question it would be nice to have posted the results of your
>research for the next guy who does a search and comes across
>your post.
>
>Jan Hyde (VB MVP)
I have no idea how to do a tiny url thing so here is a link to a
15-message thread.
Basically, I googled this group for clear collection
http://groups.google.com/group/micr...t&q=collection+
(clear)+group%3Amicrosoft.public.vb.general.discussion&rnum=1&hl=en#dec15b2612b13bd5
This does it well:
Private m_col As Collection
...
Public Sub Clear()
Do While m_col.Count > 0
m_col.Remove 1
Loop
End Sub
When I first tried to do it I was incrementing x while less than
Coll.count, but count was decreasing as I removed each item so x was
going up while count was going down, which was a recipe for failure.
I assumed that count was determined at the beginning and never
changing.
Bookreader
| |
| Bob Butler 2006-04-25, 6:57 pm |
| "Bookreader" <Bookreader127@yahoo.com> wrote in message
news:dcpq425lgiuq57qdg0h7gla6ebchq1qs6n@
4ax.com
> This does it well:
>
> Private m_col As Collection
> ...
> Public Sub Clear()
Set m_col = New Collection
> End Sub
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Jan Hyde 2006-04-25, 6:57 pm |
| richmann@sympatico.ca (bitshifter)'s wild thoughts were
released on Mon, 24 Apr 2006 19:41:54 GMT bearing the
following fruit:
>On Mon, 24 Apr 2006 09:10:04 +0100, Jan Hyde
><StellaDrinker@REMOVE.ME.uboot.com> wrote:
>
>
>Was it something like
>
>Do While coll.Count >0
> coll.remove 1
>Loop
I hope not....
J
[color=darkred]
>
Jan Hyde (VB MVP)
--
Rich foods are like destiny. They, too, shape our ends. (Art. Moger)
| |
| Bookreader 2006-04-25, 6:57 pm |
| On Tue, 25 Apr 2006 08:44:37 +0100, Jan Hyde
<StellaDrinker@REMOVE.ME.uboot.com> wrote:
>
>I hope not....
>
Why not?
Would this have something to do with my new post about
Processing elements in collection generates "The object invoked has
disconnected from its clients."
Thanks.
| |
| Jan Hyde 2006-04-25, 6:57 pm |
| Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
released on Tue, 25 Apr 2006 13:00:49 GMT bearing the
following fruit:
>On Tue, 25 Apr 2006 08:44:37 +0100, Jan Hyde
><StellaDrinker@REMOVE.ME.uboot.com> wrote:
>
>Why not?
Bob already posted a method to achieve the same thing in 1
line of code.
J
>Would this have something to do with my new post about
> Processing elements in collection generates "The object invoked has
>disconnected from its clients."
Jan Hyde (VB MVP)
--
Rich foods are like destiny. They, too, shape our ends. (Art. Moger)
| |
| Bookreader 2006-04-25, 6:57 pm |
| On Tue, 25 Apr 2006 15:40:00 +0100, Jan Hyde
<StellaDrinker@REMOVE.ME.uboot.com> wrote:
>Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
>released on Tue, 25 Apr 2006 13:00:49 GMT bearing the
>following fruit:
>
>
>Bob already posted a method to achieve the same thing in 1
>
Did "I hope not" have to do with using only one line of code, or other
consequences. As I said, I just used what other people were
suggesting when I Googled.
Did you see the other thread I started about the disconnected object
which may have been answered by now?
Thanks.
Bookreader
| |
| Jan Hyde 2006-04-26, 3:56 am |
| Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
released on Tue, 25 Apr 2006 17:06:14 GMT bearing the
following fruit:
>On Tue, 25 Apr 2006 15:40:00 +0100, Jan Hyde
><StellaDrinker@REMOVE.ME.uboot.com> wrote:
>
>Did "I hope not" have to do with using only one line of code, or other
>consequences. As I said, I just used what other people were
>suggesting when I Googled.
I mean, there is a one line solution which is quicker and
easier to use.
>Did you see the other thread I started about the disconnected object
>which may have been answered by now?
I don't recall seeing it, no.
Jan Hyde (VB MVP)
--
A friend of mine just had her 11th baby. Everyone says she's overbearing
(Megan Waves)
| |
| Bookreader 2006-04-26, 7:56 am |
| On Wed, 26 Apr 2006 09:10:30 +0100, Jan Hyde
<StellaDrinker@REMOVE.ME.uboot.com> wrote:
>Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
>released on Tue, 25 Apr 2006 17:06:14 GMT bearing the
>following fruit:
>
>
>I mean, there is a one line solution which is quicker and
>easier to use.
>
>
>I don't recall seeing it, no.
>
>
>
>Jan Hyde (VB MVP)
I still haven't had anyone tell me what the message means. What do it
mean that "the object has been disconnected from its clients?"
What are an object's clients and what does disconnected mean?
Thanks.
| |
| Jan Hyde 2006-04-26, 7:56 am |
| Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
released on Wed, 26 Apr 2006 11:19:40 GMT bearing the
following fruit:
>On Wed, 26 Apr 2006 09:10:30 +0100, Jan Hyde
><StellaDrinker@REMOVE.ME.uboot.com> wrote:
>
>I still haven't had anyone tell me what the message means. What do it
>mean that "the object has been disconnected from its clients?"
>What are an object's clients and what does disconnected mean?
The client is probably your application, and the connection
between it and whatever it was connected to is not longer in
place.
I'll see if I can find your thread.
Jan Hyde (VB MVP)
--
Three o'clock is always too late or too early for anything you want to do.
Jean-Paul Sartre
| |
| Bookreader 2006-04-26, 7:56 am |
| On Wed, 26 Apr 2006 13:13:27 +0100, Jan Hyde
<StellaDrinker@REMOVE.ME.uboot.com> wrote:
>Bookreader <Bookreader127@yahoo.com>'s wild thoughts were
>released on Wed, 26 Apr 2006 11:19:40 GMT bearing the
>following fruit:
>
>
>The client is probably your application, and the connection
>between it and whatever it was connected to is not longer in
>place.
>
>I'll see if I can find your thread.
>
>
>Jan Hyde (VB MVP)
The thread is
Processing elements in collection generates "The object invoked has
disconnected from its clients."
Thanks.
|
|
|
|
|