Set Variable

Top  Previous  Next

Available in PhraseExpander Professional

This macro stores a piece of text for later use in a variable. You can use this to store simple text or the results of a Manual Input to reuse it in your forms.

You can use a variable as a counter; you can store a number that is incremented every time the Set Variable macro is executed.

 

To store a piece of data in a variable

1.In the Phrase details pane, select the text that you want to reuse (this can be plain text or even a Manual Input).

2.Click on the Macro button macro

PhraseExpander opens the macro popup window

3.Click on Set Variable...
PhraseExpander will open the Set Variable macro window with the selected text already inserted in the contents

 

You can store a piece of text for later use with the Set Variable macro.

You can store a piece of text for later use with the Set Variable macro.

 

You can customize the Set Variable macro through the following options:

1.Text: the variable will contain some text

2.Contents: the text that will be stored in the variable

3.Counter: if checked, it creates a counter

4.Counter options:
Start at: the initial value for the counter
Increment: the value will be increased by this amount every time the macro is executed
Use fixed number of digits: sets the minimum number of digits the final result must have

5.Variable name: the name that you are going to use with the Get Variable macro to retrieve the contents. The variable name is case insensitive, so gender, Gender, GENDER will all work.

6.Insert text into the document: if checked, the text that is saved into a variable will be inserted into the generated document.

 

Syntax

 

{#varSet contents -[name][counter][start][inc][digits][hide]#}

 

contents: the data to be stored in a variable

[name]: the name of the variable that will contain the contents

[counter]: if set to 1, PhraseExpander will treat the variable as a counter

[start]: if the variable is not set, PhraseExpander will assign the start value to it (default value: 1)

[inc]: the value contained in the variable will be incremented by inc every time the macro is executed (default value: 1)

[digits]: the minimum number of digits displayed (zeros will be prepended if needed)

[hide]: if set to 1, the text will not be inserted into the phrase when executed (default value: 0)

 

Example 1: storing the result of a Manual Input

Phrase:

{#varSet {#input [Male]He::[Female]She -[desc=Gender][display=list]#} -[name=Gender]#}

 

Result:

a new variable called Gender containing a manual input is created.

 

 

Example 2: creating a counter

Phrase:

{#varSet -[name=count][counter=1][start=1][inc=2]#}

 

Result:

a new variable called count is created. Every time the macro is executed (inside the same phrase), it will increment the variable by two units (starting from 1). Output examples: 1 3 5 7...

 

NOTE: the variable set in the Set Variable macro is reset at each phrase execution. If you want to reuse the value over different executions, you have to use the Set Phrase Contents macro.