PS - merged your posts.
I'm not seeing what the actual problem is as the code you posted works. Note that I did change the reg path to a test path in HKCU where I had access rights.
When you call it the first time, if the value isn't defined and you pass the empty string, they match and the first message is displayed. When you define a value, it says it's being set and the item is created or updated. Run again with the same value and it displays the first message again. Change the value, it updates the value and displays the second message.
The second message should probably have the value var, otherwise it just says "Registry value is being set for:"
_________________________
Actually I
am a Rocket Scientist!