Last updated on: February 06, 2021
Also available as a single HTML file
Variables in macros are similar to the concept of variables in any other programming language. They can be used to temporarily store data by creating and subsequently initializing them with assignment operators. Their values can then be further manipulated or used in expressions:
$width = 5 $height = 7 $area = ($width * $height)
ForEach ($Cell in QueryObjects("Cell", GetCurrentPage())) $value = $Cell.text_numeric $value += 10 $Cell.text_numeric = $value
Variables are also used to store user input:
// Create a dialog box with some controls $dialog_box = DialogBox_Create("") DialogBox_AddTextBox($dialog_box, "&Find what", $Search, "", false) DialogBox_AddTextBox($dialog_box, "&Replace with", $Replace, "", true) $Options = Array("Current page", "Current section", "Current notebook") DialogBox_AddDropDown($dialog_box, "&Scope", $Scope, "Current section", $Options) DialogBox_AddCheckBox($dialog_box, "Match &case", $MatchCase, false) // Now show the dialog box, the user choices are stored in $Search, // $Replace, $Scope and $MatchCase variables after this call DialogBox_Show($dialog_box)
Variables in macros aren't strongly typed. Therefore they can change from one type to the other. For instance a value of "0" can be string type but modifying it by adding "1" will turn it into numeric type. However a variable always have a deterministic data type at any given point of macro execution. See Data Types for all the data types and possible values.