What I am doing? Presume 5 sample tables. I loop through the items, and use the dictionary.exists method to add only unique items. This way I get 1 dictionary object with unique values, the problem is, I use the same dictionary "IDsDict" for this, and I have to delete the dict.items so I can obtain the next set of unique IDs.
I would like to a) either "store" the dictionary seperately from the loop so that dict.RemoveAll does not effect the copy of this dictionary b) or add a new dictionary dynamically for each new run through of the loop
Is either one possible?
For uniqueRow = LBound(IDsDataFiltered, 2) To UBound(IDsDataFiltered, 2)
If Not IDsDict.Exists(IDsDataFiltered(1, uniqueRow)) Then
counter = counter + 1
globalcounter = globalcounter + 1
'Add to Dictionaries
IDsDict.Add IDsDataFiltered(1, uniqueRow), globalcounter
End If
Next uniqueRow
collUniqueDicts.Add IDsDict, timeStampsIDs
IDsDict.RemoveAll
EDIT: ultimately, I want to find out the sets of unique IDs, that are in different tables, and return other columns from those tables. Application: assume each table has ID, Timestamp, and Location. This way I can track the locations of IDs over time.
collUniqueDictsor just insert it directly. The issue with your original code, is not that the dictionary was being overriden, so much as that you were constantly using the same dictionary object.IDsDictvariable from the existing dictionary and assigns it a new one. With a function, any referenced objects - including the dictionary - are "lost" to the function after the function ends. Thus, the next function call, would result in a dictionary completely separate from any previous ones. (Exception - global vars)