Using Dynamic Variables

Applies To: AutoMate 6, AutoMate 5
Published: 11/1/04 , modified May 16, 2006


This article should be considered obsolete since the release of AutoMate 6 as a result of its ability to create and manipulate arrays.

AutoMate 5 users:

In certain instances it is useful to dynamically generate variable names. To do this a variable may be created by using the contents of another variable in the name.

Please note that in order to display the variable, the GetVarValueByVarName function must be used. This is because using %test%%loopcount% creates a double-percentage sign which resolves to a literal percent sign.


<AMVARIABLE NAME="test%loopcount%">test</AMVARIABLE>
<AMMESSAGEBOX>%GetVarValueByVarName('test' &amp; loopcount)%</AMMESSAGEBOX>

Dynamic variables are useful when there is a need to store a set of data that may occur an indeterminate number of times. In the following example the task reads the lines from a file and creates a variable for each line. In the second loop the value of the dynamic variable is displayed using the Extended Function GetVarValueByVarName().

<AMFILEREAD FILE="c:\testfile.txt" RESULTVARIABLE="thedata">
<AMLOOPLIST LIST="%thedata%" RESULTVARIABLE="currentline" DELIMITER="new_line">
<AMSET VARIABLENAME="counter">%counter +1%</AMSET>
<AMVARIABLE NAME="line%counter%">%currentline%</AMVARIABLE>

<AMLOOP FROM="1" TO="%counter%" RESULTVARIABLE="theindex">
<AMMESSAGEBOX>%GetVarValueByVarName('line' &amp; theindex)%</AMMESSAGEBOX>

Until the introduction of arrays, dynamic variables provide a useful way to store multiple records of related data.