Numeric parameters

Wondering how to send a numeric type that can be used in a calculation when using the "Execute Macro" action. Either sending a numeric parameter or is there a way to convert a string ("80") into a numeric type in the receiving macro.

Thanks.

When I first used KM I also thought there were "numeric types." There aren't. All variables are strings. Of course, they can be strings that look like numbers, eg, "3.1415" is a string that looks like a number.

KM converts strings to numbers all the time. There is no LONGINT or REAL datatype. Everything is strings.

I got used to the idea (of numbers represented only as strings) pretty quickly... and it's fine. You might think that makes KM slow. I really haven't measured it, but it sure doesn't feel slow. It's good enough for any of my purposes.

If you are having troubles writing any macro, we can help. Just post your macro.

1 Like

Here is an example... passing in a series of values and attempting to use it in a calculation. This does not work. If I substitute "80" for TriggerValue it works fine.

Calling macro

Target macro

Hi @GregM - welcome to the KM forum!

This will work:
Test Numeric Value Sub Macro.kmmacros (3.0 KB)
Keyboard Maestro Export

Following up on @tiffle's example:

%TriggerVaue% is a token, which means it's only valid in fields that take strings. When you use "Set Variable to Calculation", the "to" field is not for strings, only numbers and functions.

Yes, variables technically only hold string values. But when you use a variable in a numeric field, KM assumes it contains a number, and in fact, the operation will fail if it's not a number.

Also, when you use a variable in a numeric field, you don't include the percent signs or "%Variable%. Again, confusing, but there's a kind of logic there, too.

It took me forever to understand all of this, and I still get confused sometimes. There are visual cues that a field is numeric - for example, there isn't a drop-down allowing you to insert tokens.

5 Likes

I was hoping someone would step in and explain the complexities - it's way beyond me!

1 Like

Me too. I just keep trying to see the patterns in the UI design. Sometimes I see them, sometimes I don't. But there are more visual cues in the UI than I think most of us realize.

3 Likes

Thank you for the help! It is now working fine. I didn't realize tokens do not behave the same as variables.

3 Likes