Variables
Top  Previous  Next

Related example macros: Demo-Datasource, Demo-Slideshow

Variables are, as the name suggests, constructs that allow you to dynamically, usually during runtime, hold different values. This is very helpful when you are trying to follow links that contain changing words or when you want to use the same macro for entering different values into a search engine.

The values (content) of all variables in iMacros are accessed by putting two curly brackets around the variable name. The values of !VAR1 is thus accessed by {{!VAR1}}.

Variables can be part of anything inside the macro (except the commands themselves). For example, you can add them as part of the
ATTR string in a TAG or EXTRACT command or as part of the URL statement:

URL GOTO=https://www.onlinestore.com/?shoppingcart={{!VAR1}}&item={{!VAR2}}

You can assign almost any value to a variable. However, when assigning a value to a variable, certain characters need to be escaped or substituted because they imply a certain behaviour to iMacros. When assigning values to variables, all whitespaces in the value part must be substituted by
<SP> and all newlines must be substituted by <BR>; double curly brackets must be escaped with #NOVAR# ie. #NOVAR#{{.

There are two kinds of variables in iMacros:

Built-in variables:
These variables are used to define certain properties of the macro's behavior, for example the macro timeout value:

SET !TIMEOUT 33

There are three special built-in variables,
!VAR1, !VAR2 and !VAR3. These variable can be set to anything you like. They are also defined with the SET command

SET !VAR1 hello<SP>world

Alternatively, you can prompt the user to input a value:

PROMPT Please<SP>enter<SP>text !VAR1


User-defined Variables [PRO and Scripting Edition]
These variables are created during runtime ("on the fly") by two different mechanisms. Either one uses the command line switch
-var_MYVAR value, like so:

imacros.exe -macro myMacro -var_ITEM 15

creates the variable
ITEM during replay of the macro myMacro and gives it the value 15.

The second options is to use the
iimSet function of the Scripting Interface. In a Visual Basic Script example this would look like:

iret = imacros.iimSet("-var_ITEM", "15")




Page URL http://www.iopus.com/imacros/help/variables.htm