Numeric Calculation

Sure this has been answered elsewhere but cannot get my head round syntax.
I am copying numeric value to system clipboard and setting variable X_axis to system clipboard.
Then tabbing through to next field and repeating copy and setting variable Y_axis to new system clipboard value. I want to create an if-then based on result of calculating if a) X_axis = Y_axis or b) X_axis > Y_axis or c) obviously X_axis < Y_axis - but cannot figure out how to do the calculation as options only seem to be for string/text tests. When I check the values are of the form .16' and .09' so not sure if this makes any difference.

Help much appreciated.

Well, .16' is not a valid number, because of the trailing ' character.

You need to remove that from your variable. You could use a Search and Replace action.

Then your calculation will work.

The non numeric character makes sense and I should have spotted that. (But learnt something else from your reply :slight_smile: Have displayed clipboards so know that is working.

However, calculation is not. I have tried disabling/enabling and various combinations of

Set Variable ‘X_axis’ to Text ‘%Calculate%X_axis’
Set Variable ‘Y_axis’ to Text ‘%Calculate%Y_axis’
%X_axis%=%Y_axis% and
None display the text (this is just quick step for me to check if calculation is working).

What am I missing?

Hey Michael,

Since you haven't posted a testable macro it's hard to tell...

Rule-of-the-thumb ⇢ When things aren't working ⇢ Simplify.

This is a working example:

Download Calculation Test.kmmacros (5.5 KB)

Check your values in the variables panel of the Keyboard Maestro Editor preferences.

Make sure you don't have some funky artifacts or spaces in them.

Turn everything off that you can and enter values for your variables with Set Variable to Text actions, so you absolutely know what they are.

If that works then you're missing something in your data acquisition and processing.

You can troubleshoot from the top down and look for where things go wrong.

Or you can start from where you KNOW things ARE wrong and work your way up to try and detect WHERE things go awry.


Check out the Text Fields page on the wiki which will probably clear up some of your issues.