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
Re: simple way to clear a collection in VB6?
Set domainhideimageurl = Nothing
Set domainhideimageurl = New Collection
How about that?
-tg
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
Re: simple way to clear a collection in VB6?
Quote:
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.
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
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
Re: simple way to clear a collection in VB6?
Quote:
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?
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
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
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.
Re: simple way to clear a collection in VB6?
Understood. I thought this was in reference to VB6. Sgarv