Run Macro in Variable

 

Macro Express allows the contents of a variable to be loaded during the playback of a macro and executed as part of the macro. This can be used to change the behavior of the macro as it runs.

 

The "Run Macro in Variable" command is similar to the "Load Macro Text File" command, but because there is no file I/O, the "Run Macro in Variable" command runs much faster.

 

 

Script Editor > Expand Variables Category > Run Macro in Variable

 

 

Script Editor vs Direct (ASCII) Editor

When creating a macro that will run in a variable it needs to be written in ASCII format.

 

In the Script Editor, macro commands are displayed in an easily recognized and understood format. To achieve this simplicity, some of the details about each command are only displayed in the edit dialog for the macro command.

 

In the Direct Editor, all details about each macro command are visible. When describing these two ways of viewing macros, we refer to them as the Script and ASCII representations.

 

To view the ASCII representation of a macro click View > Direct Editor. Note that when in the Direct Editor view, all open macros are displayed in their ASCII form.

 

Another way to see the ASCII representation of a macro or macro commands is to highlight the commands you want to view, while in the Script Editor, and paste them into another program such as Notepad.

 

 

Examples

Script Format

ASCII Format

Text Type (Simulate Keystrokes): Text Type example

<TEXT TYPE Action="0" Text="Text Type example"/>

Variable Set String %Colors% to "blue"

<VARIABLE SET STRING Option="\x00" Destination="%Colors%" Value="blue"NoEmbeddedVars="FALSE"/>

If Variable %Colors% Equals "Blue"

<IF VARIABLE Variable="%Colors%" Condition="\x00" Value="Blue" IgnoreCase="FALSE"/>

 

 

Dynamically Create Macros

Macro Express Pro allows you to dynamically create macros. You can use one or more macros to create other macros that are different depending on events and choices that occur as the macro runs. In order to do this you need to put the ASCII representation of the macro commands that make up your macro into a variable.

 

For example, to include a Text Type command in the variable %RunThis% you would need to set the content of the %RunThis% variable.

 

    Variable Set String %RunThis% "<TEXT TYPE Action="0" Text="A Text Type example"/>"

 

 

Expansion of Variables

Normally commands that deal with variables substitute the contents of a variable for the variable name. For example, %FirstName% will be changed to something like George. When using the Run Macro in Variable command, often the name of a variable is needed instead of the content of the variable. Up until now, the automatic substitution with the content of a variable has made it awkward to use the Run Macro in Variable command.

 

The option 'Do not process embedded variables' has been added to many of the Variable Set String and Variable Modify String commands. This makes it easier to create a variable that contains variable names for use in the Run Macro in Variable command.

 

We have added another method of specifying a variable name. If you surround the variable name with {%} then the content of the variable will not be used. Instead the name of the variable will be passed to the Run Macro in Variable command. If you include {%}FirstName{%} it will be changed to %FirstName% in the Run Macro in Variable command. If you include %FirstName%, the content of the variable will be passed to the Run Macro in Variable command.

 

 

A) When a variable is included in a macro command, the content of the variable is used when the macro runs. Consider this example:

 

    Variable Set String %My% to "My example"
    Variable Set String %RunThis% "<TEXT TYPE Action="0" Text="%My% of the Text Type command"/>"

 

When this runs the %RunThis% variable will become "<TEXT TYPE Action="0" Text="My example of the Text Type command"/>"

 

 

B) There are times, however, when you want the %FirstName% variable to contain the name of a variable, not its content. To do this change the command to look like this:

 

Variable Set String %FirstName% "<VARIABLE SET STRING Option="\x00" Destination="{%}FirstName{%}" Value="%Name%" NoEmbeddedVars="FALSE"/>"

 

The value "{%}FirstName{%}" will be changed to %Name% and will not be changed to the content of variable %Name%.

 

üNote: If you need to include the value {%} in your macro use this {{%}}. It will be changed to {%}.

 

 

C) Another way to encode a variable is to use the \c parameter. This option expects two hexadecimal digits to represent a single character. The sample above may be written this way:

 

Variable Set String %RunThis% "<VARIABLE SET STRING Option="\x00" Destination="\c25FirstName\c25" Value="%Name%" NoEmbeddedVars="FALSE"/>"

 

This works because 25 is the hexadecimal value for %. The \c is case sensitive, \C will not work.

 

üNote: When including file paths in the Run Macro in Variable command, be careful when including certain characters in the path. For example, if needing to include a path like c:\charlie the \c will be interpreted as a hexadecimal character command. There are two ways to avoid this problem. You can change the case to avoid this situation by using c:\Charlie, for example. Or you may use a double backslash: c:\\charlie.