CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1

    deleting duplicate items from collection?

    how to delete or find out duplicate items from a collection. i mean looking for a fast alogorithm which can do this.. or do you know how to catch the error when a duplicate key is added to a collection?


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: deleting duplicate items from collection?

    VB does not allow duplicates in a collection if you use the Key argument to the Add method of the collection object.
    Simply trap the runtime error as in

    dim col as new collection
    on error goto erradd
    col.add Key:=mykey, Item:=myItem
    exit sub
    erradd:
    ' handle error here





  3. #3

    Re: deleting duplicate items from collection?

    i used this when i put in the key, but when not using the key there would be duplicates in the collection. i guess you got to write your own collection and then check the item you add before putting them in the collection.


  4. #4

    Re: deleting duplicate items from collection?

    See http://www.freevbcode.com/ShowCode.Asp?ID=40.
    This is a function that evaluates a list (array or collection) and returns false if it does not contain unique values. You can easily modify it to return a collection of unique values instead.


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: deleting duplicate items from collection?

    you might even be better off by using the
    Dictionary
    object in VB 6!
    it's faster and has more methods...


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

Featured