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 > Concepts > Arrays

Arrays

Variables can store a single value or a set of values. Variables that store a set of values are of Array data type. Arrays can store an unbounded amount of <key, value> pairs. The values are always accessed by providing the key (known as index). New elements can be added to arrays by assignment and specifying the a key that doesn't exist in the array:

Creating Arrays

$Names[0] = "Fred" $Names[1] = "Kate" $Names[2] = "Sally"

Arrays can also be created by Array function by simply providing the list of elements:

$Names = Array("Fred", "Kate", "Sally")

Here the indices are autmatically assigned as 0, 1, 2

Iterating over Array Elements

Values in the array can be iterated over using ForEach statements

ForEach ($Name in $Names) InsertObject($Outline, "Paragraph", -1).text = $Name

Array keys are of string or numeric types and they don't have to follow any order.

Array functions

There are a several functions that generate and consume arrays. QueryObjects and QueryText functions return arrays of objects. String_Split function splits a given string into an array of strings, while Array_Join function reverses this. Array_Length function will return the number of elements in an array.

Using an array as a stack or a queue

Array_PopFront and Array_PushBack functions can be used as equivalents of dequeue and enqueue operations on a queue data structure. Similarly Array_PushBack and Array_PopBack functions allow an array to be used as a stack, providing simple push/pop functionality. Finally there is an Array_PushFront function to insert an element at the beginning of an array.

Multi-dimensional Arrays

Arrays can be multi-dimensional if they contain other arrays:

$Names = Array(Array("Fred", "Williams"), Array("Kate", "Smith"), Array("Sally", "Jones")) $SallysLastName = $Names[2][1]

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