How to delete a dictionary or a key?

I'm just figuring how to implement KM dictionaries in my macros but it's hard to find enough material on web. While experimenting I created many dictionaries and keys. How can I delete specific dictionaries or specific keys for a dictionary?

I have a large number of dictionaries that I regularly need to delete so this is how I do it:

KM 1 2020-11-10_18-19-04

In step 1 I loop through all the dictionaries whose name contains "DWM" and then...

In step 2 for each of those dictionaries I loop through each of their keys and set them to empty.

Your case may be different: the dictionaries you want to delete may not have something in common (like the "DWM" in mine) and you may not want to delete all the keys in them like I do.

So, in summary, to delete a dictionary you:

  1. set all its keys to the empty text.

When you've done that, the dictionary is no more! Hope that helps.


Thank you for your fast response. I have a similar for each setup to set the values. But I didn't know that a dictionary deletes itself when the keys are empty. That's really useful. I'll try it now. Thanks!

I have a few questions about your macro. Is there a particular reason you named your variables starting with "Local_"?
Also in the state "...set each value to nothing" you used %Local_dic% without adding %Variable% in front of it. Why is that?

Glad to be of help...

I use local variables wherever I can as, when the macro finishes, they disappear and so don’t clutter up KM. I would normally prefix all my variable usage with %Variable% so I guess I just forgot it here. I did write this a long time ago, so if there was a reason for omitting it I can’t remember why!

Oh I should switch to using local variables then. My variables list looks like a mess. Thanks for your help!

1 Like