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/03/13 08:48]
AlainLifchitz JMTX template + robuster Google search
action:Set_Variable_to_Calculation [2023/11/10 22:40] (current)
peternlewis [Formatting]
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 field, so you can set a variable whose name changes.+You may use the following in the //to// calculation box:
  
-===== See Also =====+  * [[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 a [CALCULATE](https://​wiki.keyboardmaestro.com/​function/​CALCULATE) function.
  
-=== Actions ​===+===== Variables =====
  
-* [[action:​Set Variable to Keychain Password|action:Set Variable to Keychain Password]] +The //to// field is a numeric field, so you use variable names unadorned:​ 
-* [[action:​Set Variable to Text|action:Set Variable to Text]]+ 
 +  * Do **not** use the text token syntax for a Variable, like `%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 action, specifically you can //Format the Result// using [[https://​www.stairways.com/​action/​linkthru?​unicodenumberformat|Unicode Number Format Patterns]] such as //#,##​0.##//​. 
 + 
 +(i) Note that numeric values in Keyboard Maestro allow only “full stop” decimal (.) and no thousand separators (except optional underscores),​ so the output of this action with formatting will likely not be a valid number for a Keyboard Maestro calculation in many locales. **It should be used only for display purposes.** 
 + 
 + 
 +===== 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 a 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 ===== 
 + 
 +==== 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]] * [[:​Actions|See all Actions]]
  
-=== Functions ===+==== Functions ​====
  
 * [[function:​CEIL|CEIL()]] * [[function:​CEIL|CEIL()]]
Line 27: Line 67:
 * [[:​Functions|See all Functions]] * [[:​Functions|See all Functions]]
  
-----+==== Tokens ==== 
 + 
 +* [[token:​Calculate|%Calculate%]] token 
 +* [[token:​CalculateFormat|%CalculateFormat%]] token 
 +* [[:​Tokens|See all Tokens]] 
 + 
 +==== Topics ==== 
 + 
 +* [[:Text Fields|Text Fields]] 
 +* [[:​Frequently Asked Questions|FAQ]]
  
 ==== 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/​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/search?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.1457873323.txt.gz · Last modified: 2016/03/13 08:48 by AlainLifchitz