0

I'm trying to replace an old dictionary value with a new collection. I cannot figure out why the key that is being found is not getting deleted. I changed the .CompareMode to TextCompare but still cannot successfully delete the string. Updating the value of the dictionary didn't work either, so I tried to remove then add again. Reference

How can I remove and add back (or update) the key/value pair of the dictionary?

collStr = "testvalue"
c.Add (collStr)

If dict.Exists(Key) Then
   dict.Remove Key         '<- This should remove but still appearing in 'Watches' dictionary
If Not dict.Exists(Key) Then
   dict(Key) = c           '<- Trying to replace only dictionary value with new collection
   'dict.Add Key, c
End If

before-removing-key

after-removing-key

William Humphries
  • 541
  • 1
  • 10
  • 21
  • 3
    `Set dict(Key) = c` since you're setting an object reference (collection). – Kostas K. Jun 26 '20 at 15:48
  • 3
    If you put a watch on a dictionary then just referring to the key in the Watch window can re-add the key, so be wary of what you see when using a Watch on a dictionary... Previously - https://stackoverflow.com/questions/48896394/dictionary-exists-returning-different-values-for-variable-and-constant-key/48896896#48896896 – Tim Williams Jun 26 '20 at 16:17
  • @KostasK. if you give as answer, I will accept then delete this comment – William Humphries Jun 26 '20 at 16:43

0 Answers0