Nate Bross Posted January 29, 2006 Posted January 29, 2006 I have two collections of custom class objects like this. Dim NewItems as Collection Dim OldItems as Collection Every user defined amount of time NewItems will be cleared and populated. I need to figure out if there is an item in NewItems that IS NOT in OldItems and if there is add it to a third collection. I am trying to use the following code to check if the item is a re-occurance. If OldItems.Count <> 0 Then For Each OldItem As Item In OldItems For Each NewItem As Item In NewItems If NewItem.ItemID() IsNot OldItem.ItemID() Then UnViewed.Add(NewItem) Exit For End If Next Next Else OldItems = NewItems End If The problem is that I get three hundred of the same entery into my UnViewed collection. If anyone could help me with the logic of this, I'd really appreciate it. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted January 29, 2006 Administrators Posted January 29, 2006 Rather than using Collections you are probably better off with something like an ArrayList - you can then simply use the .IndexOf method to check to see if an item is in the ArrayList rather than looping through them yourself. IIRC Collection is really nothing more than the VB6 collection object and as such doesn't have the same features of the newer collection / list classes. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nate Bross Posted January 30, 2006 Author Posted January 30, 2006 Good call, I'll look into that and see how that works. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.