Results 1 to 11 of 11

Thread: simple way to clear a collection in VB6?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    65

    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

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: simple way to clear a collection in VB6?

    Set domainhideimageurl = Nothing
    Set domainhideimageurl = New Collection

    How about that?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    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

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    65

    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

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    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

  7. #7
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: simple way to clear a collection in VB6?

    Quote Originally Posted by kidoflion View Post
    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?

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    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

  10. #10
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    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.

  11. #11
    Member sgarv's Avatar
    Join Date
    Jul 2012
    Posts
    34

    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
  •  



Click Here to Expand Forum to Full Width