Although the AutoMate library of available actions provides a robust set of functionality that may be configured visually, occasionally it may be necessary to utilize straight BASIC scripting to access API calls or COM objects or to perform other complex tasks. This can be done using the built-in BASIC scripting engine. These BASIC scripts may be embedded directly into a task file, or alternatively may reference an external BAS file.
An example of this type of usage is shown below.
NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.
<AMSHOWDIALOG ACTIVITY="input" RESULTVARIABLE="NUMTOSQUARE">Which number would you like squared?</AMSHOWDIALOG>
theresult = NUMTOSQUARE * NUMTOSQUARE
theresult = "The result is" & Str(theresult)
<AMSHOWDIALOG RESULTVARIABLE="NUMTOSQUARE">The result of the entered number squared is %theresult%.</AMSHOWDIALOG>
BASIC scripting can also be used for creating Custom Functions. A custom function performs a calculation, and may be used as many times as needed as an expression in future steps. In fact, the above task would be more efficient if created in this manner.
An example of the same task restructured with a custom function is shown below:
<AMSHOWDIALOG ACTIVITY="input" RESULTVARIABLE="NUMTOSQUARE" WINDOWTITLE="Please enter a number">Which number would you liked squared?</AMSHOWDIALOG>
SquareNumber = thenumber * thenumber
<AMSHOWDIALOG>The result of the entered number squared is %SquareNumber(NUMTOSQUARE)%</AMSHOWDIALOG>
<AMSHOWDIALOG>The result of the squared number squared is %SquareNumber(SquareNumber(NUMTOSQUARE))%</AMSHOWDIALOG>
As you can see, the basic script was converted into a custom function so that it can be called multiple times in the task and so that different values may be passed to it for processing. The function will of course yield a different result depending on the value passed to it.
BASIC Script Action
Introduction to BASIC scripting
The BASIC Language Grouped by Type
Introduction to Extended Functions
BASIC Script Action | Introduction to BASIC scripting | The BASIC Language Grouped by Type | Introduction to Extended Functions