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/30 03:06]
peternlewis [Set Variable to Calculation Action]
action:Set_Variable_to_Calculation [2023/11/10 22:40] (current)
peternlewis [Formatting]
Line 1: Line 1:
-{{:​action:​calculator-icon.png?​nolink|}} 
 ====== Set Variable to Calculation Action ====== ====== Set Variable to Calculation Action ======
  
 The Set Variable to Calculation action sets a variable to the result of a calculation with numeric formatting. The Set Variable to Calculation action sets a variable to the result of a calculation with numeric formatting.
  
-{{:​action:​km7-set-var-name-to-calculation-action.png?​nolink|}}\\ +{{:​action:​km7-set-var-name-to-calculation-action.png?​nolink|}} 
-**You may use the following in the //to// calculation box:**+ 
 +===== Calculations ===== 
 + 
 +You may use the following in the //to// calculation box: 
   * [[token:​Variable|Keyboard Maestro Variables]]   * [[token:​Variable|Keyboard Maestro Variables]]
   * [[:​Functions|Functions]]   * [[:​Functions|Functions]]
-  * [[https://www.keyboardmaestro.com/​documentation/​7/​calculations.html|Calculation Operators]]+  * [[/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]]. ​ +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. 
 + 
 +===== Variables ===== 
 + 
 +The //to// field is a numeric field, so you use variable names unadorned:
  
-**Using Keyboard Maestro Variable Names in the //to// calculation box:** 
   * Do **not** use the text token syntax for a Variable, like `%Variable%My Variable Name%`.   * 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`   * Instead, you just use the Variable name without any `%`, like `My Variable Name`
  
 You can use the //Edit ➤ Insert Function// menu to insert functions. 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.##//​. 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.##//​.
-===== Example ​=====+ 
 +(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. 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.
Line 25: Line 47:
 {{:​action:​km7-set-var-to-calculation-macro.png?​nolink|}} {{:​action:​km7-set-var-to-calculation-macro.png?​nolink|}}
  
 +==== Example 2 ====
  
-===== See Also =====+{{vars-x-y-width-height.png?​597;​nolink|}}
  
-----+===== See Also =====
  
 ==== Actions ==== ==== Actions ====
  
-* [[action:​Set Variable to Keychain Password|action:Set Variable to Keychain Password]] +* [[action:​Set Variable to Keychain Password|Set Variable to Keychain Password]] 
-* [[action:​Set Variable to Text|action:Set Variable to Text]]+* [[action:​Set Variable to Text|Set Variable to Text]]
 * [[:​Actions|See all Actions]] * [[:​Actions|See all Actions]]
  
Line 44: 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.1459321619.txt.gz · Last modified: 2016/03/30 03:06 by peternlewis