User Tools

Site Tools


action:Set_Variable_to_Calculation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
action:Set_Variable_to_Calculation [2016/02/24 04:37]
AlainLifchitz cosmetic change
action:Set_Variable_to_Calculation [2023/09/20 02:26] (current)
peternlewis
Line 1: Line 1:
-The Set Variable to Calculation ​action sets a variable to the result of a calculation with numeric formatting. Also see the Calculations section.+====== ​Set Variable to Calculation ​Action ======
  
-{{:action:​setvariabletocalc.png|200}}+The Set Variable to Calculation ​action ​sets a variable to the result of a calculation with numeric formatting.
  
-Select the variable to set from the //Set variable// pop-up or enter a variable ​name.+{{:​action:​km7-set-var-name-to-calculation-action.png?​nolink|}}
  
-Enter a calculation in the //to// text area. The result is displayed at the bottom of the action.+===== Calculations =====
  
-Unlike most places ​you specify ​a variable, the variable ​name itself ​is a text token fieldso you can set a variable ​whose name changes.+You may use the following in the //to// calculation box: 
 + 
 +  * [[token:​Variable|Keyboard Maestro Variables]] 
 +  * [[:​Functions|Functions]] 
 +  * [[/​manual/​Calculations|Calculation Operators]] 
 + 
 +The //to// field is a [[:​Text_Fields|numeric field]] so you cannot use any of the [[token:​CurrentClipboard|Clipboard tokens]] or indeed any [[:​Tokens|text tokens]], except within ​[CALCULATE](https://​wiki.keyboardmaestro.com/​function/​CALCULATE) function. 
 + 
 +===== Variables ===== 
 + 
 +The //to// field is a numeric field, so you use variable ​names unadorned:​ 
 + 
 +  * Do **not** use the text token syntax for a Variablelike `%Variable%My Variable Name%`. 
 +  * Instead, you just use the Variable ​name without any `%`, like `My Variable Name` 
 + 
 +You can use the //Edit ➤ Insert Function// menu to insert functions. 
 + 
 +===== Formatting ===== 
 + 
 +As can be seen by the blue shade of the action gear menu there is an additional option for the actionspecifically ​you can //Format the Result// using [[https://​www.stairways.com/​action/​linkthru?​unicodenumberformat|Unicode Number Format Patterns]] such as //#,##​0.##//​. 
 + 
 +===== Result ===== 
 + 
 +At the bottom of the action you can see the current value of the calculation. 
 + 
 +If the calculation is invalidly formatted, the invalid part of the calculation will show up in <color #​ed1c24>​RED</​color>​. 
 + 
 +If the calculation would currently fail because an input variable does not currently have numeric value, that variable ​will show up in <color #​ff7f27>​ORANGE</​color>​. 
 + 
 +===== Examples ===== 
 + 
 +==== Example 1 ==== 
 + 
 +The below macro performs a simple calculation of adding 1 to the value currently selected by the user in the user's document, and then pasting the new value back into the user's document. 
 + 
 +{{:​action:​km7-set-var-to-calculation-macro.png?​nolink|}} 
 + 
 +==== Example 2 ==== 
 + 
 +{{vars-x-y-width-height.png?​597;​nolink|}}
  
 ===== See Also ===== ===== See Also =====
  
-==== Documentation ​====+---- 
 + 
 +==== Actions ​==== 
 + 
 +* [[action:​Set Variable to Keychain Password|Set Variable to Keychain Password]] 
 +* [[action:​Set Variable to Text|Set Variable to Text]] 
 +* [[:​Actions|See all Actions]] 
 + 
 +==== Functions ==== 
 + 
 +* [[function:​CEIL|CEIL()]] 
 +* [[function:​FLOOR|FLOOR()]] 
 +* [[function:​ROUND|ROUND()]] 
 +* [[function:​TRUNC|TRUNC()]] 
 +* [[:​Functions|See all Functions]] 
 + 
 +==== Topics ==== 
 + 
 +* [[:Text Fields|Text Fields]] 
 +* [[:​Frequently Asked Questions|FAQ]] 
 + 
 +----
  
-* [[action:​Set Variable to Keychain Password|action:​Set Variable to Keychain Password]] 
-* [[action:​Set Variable to Text|action:​Set Variable to Text]] 
-* [[function:​CEIL|function:​CEIL]],​ [[function:​FLOOR|function:​FLOOR]],​ [[function:​ROUND|function:​ROUND]],​ [[function:​TRUNC|function:​TRUNC]] 
 ==== Forum ==== ==== Forum ====
  
 +- [[https://​forum.keyboardmaestro.com/​t/​how-to-access-a-text-array-variable/​507|How to access a text array variable]]
 - [[https://​forum.keyboardmaestro.com/​t/​need-help-doing-time-based-calculations/​2730/​2|Need Help Doing time based calculations]] - [[https://​forum.keyboardmaestro.com/​t/​need-help-doing-time-based-calculations/​2730/​2|Need Help Doing time based calculations]]
 - [[https://​forum.keyboardmaestro.com/​t/​round-to-1-decimal-place/​3001/​2|Round to 1 decimal place]] - [[https://​forum.keyboardmaestro.com/​t/​round-to-1-decimal-place/​3001/​2|Round to 1 decimal place]]
 +- [[https://​forum.keyboardmaestro.com/​t/​how-to-create-an-if-else-calculation/​3047/​5|How to create an if else calculation?​]]
 +- [[https://​forum.keyboardmaestro.com/​t/​km-delete-all-variables-except-those-on-keep-list/​3428|[KM] DELETE All Variables Except Those on Keep List]]
 +- [[https://​forum.keyboardmaestro.com/​t/​feature-request-finding-macros-that-use-a-variable/​3439/​2|(Feature Request?) Finding macros that use a variable]]
 +- [[https://​forum.keyboardmaestro.com/​t/​variable-naming-conventions/​3444/​2|Variable Naming Conventions?​]]
 +- [[https://​forum.keyboardmaestro.com/​t/​can-i-create-a-structure-type-of-variable/​3557/​6|Can I create a "​structure"​ type of variable?]]
  
-- [[https://www.google.fr/webhp?aqs=chrome..69i57.14628j0j7&​gws_rd=cr&​ei=_BSvVse8Ecb9acLtidAB#​q=site:​forum.keyboardmaestro.com+Set+Variable+Calculation|Keyboard Maestro Forum topics about Set Variable to Calculation]]+- [[https://forum.keyboardmaestro.com/search?q=Set%20Variable%20Calculation|Keyboard Maestro Forum topics about Set Variable to Calculation]]
action/Set_Variable_to_Calculation.1456306663.txt.gz · Last modified: 2016/02/24 04:37 by AlainLifchitz