Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...