-
Mar 28th, 2007, 10:13 PM
#1
Thread Starter
Lively Member
simple way to clear a collection in VB6?
Hi
To clear a collection i am doing in this way. Is there any better and easiest way to do that.
urlcount1 = 0
urlcount1 = domainhideimageurl.count
If urlcount1 > 0 Then
e = urlcount1
Do Until e = 0
domainhideimageurl.Remove (e)
e = e - 1
Loop
End If
please let me know.
thanks
srinivasa
-
Mar 28th, 2007, 10:36 PM
#2
Re: simple way to clear a collection in VB6?
Set domainhideimageurl = Nothing
Set domainhideimageurl = New Collection
How about that?
-tg
-
Mar 28th, 2007, 10:38 PM
#3
Re: simple way to clear a collection in VB6?
This is how it is done in an MSDN example:
Code:
For i = 1 to MyCollection.Count
MyCollection.Remove 1 ' Remove first item
Next i
-
Mar 28th, 2007, 10:47 PM
#4
Re: simple way to clear a collection in VB6?
Originally Posted by Logophobic
This is how it is done in an MSDN example:
Code:
For i = 1 to MyCollection.Count
MyCollection.Remove 1 ' Remove first item
Next i
Don't do it this way... DO it the way techgnome suggested. It's cleaner and faster.
-
Mar 28th, 2007, 10:54 PM
#5
Thread Starter
Lively Member
Re: simple way to clear a collection in VB6?
Thank you. This is working.
Set domainhideimageurl = Nothing
Set domainhideimageurl = New Collection
But can u also let me know how can we check whether an element is there in a collection or not?
let me know
srinivas
-
Mar 28th, 2007, 10:58 PM
#6
Re: simple way to clear a collection in VB6?
The quickest way I know is
domainhideimageurl.add Element
if you get an error, it is there already. You may need to use a key also ie.
domainhideimageurl.add Element, ElementName
-
Jul 7th, 2012, 06:53 PM
#7
Frenzied Member
Re: simple way to clear a collection in VB6?
Originally Posted by kidoflion
Set domainhideimageurl = Nothing
Set domainhideimageurl = New Collection
Does this work if I already DIMed it as a new collection?
I didn't DIM it as a collection, and then set it to a NEW collection. Instead I DIMed it as a NEW collection to start with. Will this have to be cleared differently? Or will your technique still work?
-
Jul 7th, 2012, 07:30 PM
#8
Re: simple way to clear a collection in VB6?
wow a 5 year old thread.... anyways... two things... 1) in the amount of time that it took for someone to come across your post and give you the answer (which yes, it'll still work) you could have tried it yourself and seen that it would have worked. And secondly, yes.
-tg
-
Jul 7th, 2012, 10:29 PM
#9
Member
Re: simple way to clear a collection in VB6?
For posterity?
Code:
Dim colNXS as Collection
set colNXS = new collection
'Work with collection
'Clear collection
colNXS.Clear
-
Jul 7th, 2012, 11:05 PM
#10
Re: simple way to clear a collection in VB6?
A VB6 VBA.Collection object doesn't have a Clear method - just set it to a New VBA.Collection to clear it.
-
Jul 8th, 2012, 09:01 PM
#11
Member
Re: simple way to clear a collection in VB6?
Understood. I thought this was in reference to VB6. Sgarv
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|