How to you refer to Variables that have spaces in their names in calculations?

In general I would avoid using a space as part of a variable name, but given that KM allows it I've used it in a prompt for user input, e.g., "localAge years". This works fine in use as a text token (%Variable%localAge years%) but now I want to use it in a calculation, e.g, assign a new variable to the value... localAge years + 1. Adding the % notation as for texts fails too. So how does one use space-containing variables in calculations... or is this a no no?

There's no general problem in using variable names with spaces in Calculation fields, so I suspect the problem is elsewhere. Post your macro and, hopefully, someone will spot it.

If there's a specific name problem in your macro (perhaps there's another variable "localAge" that's confusing things?) you could try making the variable name "atomic" by using a variable token in a CALCULATE function in your Calculation field -- trust me, that sounds a lot worse than it actually is!

See below for examples of both a working "spaced name" and, after that, the token trick.

Space Test.kmmacros (2.4 KB)

Summary

1 Like

Thanks very much Nige... your explanation and example were great... even the atomic option (which is highlighted in Red by KM to make it even more scary!).
Your example prompted me to go back through my own macro and to evaluate each variable at each step (using localAge Year etc)... and low and behold it works fine... so your initial suspicion was correct... I don't know what I had done, but likely a typo that I didn't repeat the second time around.... So again, many thanks