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?
Printable View
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?
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
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.
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.
you might even be better off by using the
Dictionary object in VB 6!
it's faster and has more methods...