|
Onetastic Macro Documentation >
>
Storing persistent data
Storing persistent data
You can store and retrieve data for a particular macro on the local computer by using the LocalStore_Write and LocalStore_Read functions. The data stored by LocalStore_Write can be read back on a separate execution of the same macro, allowing data to be persisted accross multiple executions. Data cannot be shared between different macros.
Improving dialog boxes with persistent data
One very useful way to use persistent data is to store and remember user input for subsequent executions of a macro. For instance, the Search & Replace macro remembers the values user entered in the dialog box so that it can present those same values when the user runs the macro again. Similarly, settings in a macro, like which day of the week the calendar should start for the Insert Monthly Calendar macro, can be stored and retrieved.
Copied!
if (!LocalStore_Read("LastSearch", $Search))
$Search = ""
if (!LocalStore_Read("LastReplace", $Replace))
$Replace = ""
if (!LocalStore_Read("LastScope", $Scope))
$Scope = "Current section"
if (!LocalStore_Read("LastMatchCase", $MatchCase))
$MatchCase = false
$dialog_box = DialogBox_Create("")
DialogBox_AddTextBox($dialog_box, "&Find what", "Search", $LastSearch, false)
DialogBox_AddTextBox($dialog_box, "&Replace with", "Replace", $LastReplace, true)
$Options = Array("Current page", "Current section", "Current notebook")
DialogBox_AddDropDown($dialog_box, "&Scope", "Scope", $LastScope, $Options)
DialogBox_AddCheckBox($dialog_box, "Match &case", "MatchCase", $LastMatchCase)
DialogBox_Show($dialog_box)
$Search = $dialog_box.controls["Search"]
$Replace = $dialog_box.controls["Replace"]
$Scope = $dialog_box.controls["Scope"]
$MatchCase = $dialog_box.controls["MatchCase"]
LocalStore_Write("LastSearch", $Search)
LocalStore_Write("LastReplace", $Replace)
LocalStore_Write("LastScope", $Scope)
LocalStore_Write("LastMatchCase", $MatchCase)
|