I have a dictionary dictA that contains {AA,1},{AB,2},{AC,3} and an adjustment dictionary dictAdj containing {AB,-4}.
I pass these two into a function call it funcReconcile(ByVal Arg1 as Dictionary, ByVal Arg2 as Dictionary) as Dictionary.
The function is going to loop through the contents of dictAdj to see if they exist in dictA.
The function will then adjust dictA (for example) to show {AA,1},{AB,-2},{AC,3} in the output dictionary.
For some reason, when the function returns the dictionary, my original dictA is also effected, causing it to display {AA,1},{AB,-2},{AC,3} and not {AA,1},{AB,4},{AC,3} as it should.
I know there are issues in VBA with passing ByRef and ByVal for objects, but this is the first time really hitting my head against the wall with something like this.
Any pointers? (no pun intended)
You would have to build a copy method, make a complete copy of the dictionary, and then make modifications on the copy.
Assigning to a new variable just assigns the original reference to the new variable — which points back to the original data.
Here’s some fragmentary code from Copy from one dictionary object into another?: