Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macro Statements

Expression Editor

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: March 19, 2023
Also available as a single HTML file

Onetastic Macro Documentation > How To > 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 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 Insert Monthly Calendar macro, can be stored and retrieved.
// Check if we have values stored from a previous run // If so, we will use them as initial values of dialogbox controls ExpandIf (!LocalStore_Read("LastSearch", $Search)) $Search = "" ExpandIf (!LocalStore_Read("LastReplace", $Replace)) $Replace = "" ExpandIf (!LocalStore_Read("LastScope", $Scope)) $Scope = "Current section" ExpandIf (!LocalStore_Read("LastMatchCase", $MatchCase)) $MatchCase = false // Create a new dialog box $dialog_box = DialogBox_Create("") // Now add some controls 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) // Now show the dialog box DialogBox_Show($dialog_box) // We can now use the values for the controls using $dialog_box.controls $Search = $dialog_box.controls["Search"] $Replace = $dialog_box.controls["Replace"] $Scope = $dialog_box.controls["Scope"] $MatchCase = $dialog_box.controls["MatchCase"] // Now store these values so that we can read them back in a subsequent run LocalStore_Write("LastSearch", $Search) LocalStore_Write("LastReplace", $Replace) LocalStore_Write("LastScope", $Scope) LocalStore_Write("LastMatchCase", $MatchCase)

Reference

Statements

For

ForEach

If

Else If

Else

Switch

Case

Default

While

Expression

Comment

Break

Continue

Return

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

MacroMenu

Window

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

String Functions

Window Functions