BASIC Scripts & Custom Functions
Overview
Automate Desktop's library of actions and activities offer a robust set of functionality that can be started automatically and configured visually. However, during certain occasions, it may be necessary to apply BASIC scripting to perform complex operations, such as accessing API calls or COM objects, implementing server-side scripting, and much more. Automate Desktop's solution is its full-featured Visual Basic for Applications compliant scripting language combined with a built-in BASIC scripting engine.
The scripting engine integrates seamlessly into the existing Automate Desktop framework, appearing as an extra IDE in the macro builder called 'Run a Script'. In an automated procedure, you may have an unlimited number of 'script' steps, making decisions, handling complex File I/O routines, etc. The added flexibility of the Automate Desktop BASIC Scripting Language is that an unlimited number of customized Automate Desktop- oriented commands can be added to the language to make life (and automation) easier for you.
Automate Desktop's built-in BASIC scripting engine can further enhance scripts by fully automating them. Scripts may be embedded directly into a task file, or alternatively, may reference an external BAS file. See BASIC Script action for more details.
Example:
<AMVARIABLE NAME="NUMTOSQUARE" VALUE="1" />
<AMVARIABLE NAME="theresult" />
<AMSHOWDIALOG ACTIVITY="input" MESSAGE="Please enter a number that you would like squared." RESULTVARIABLE="NUMTOSQUARE" />
<AMSCRIPT>Sub Main theresult = NUMTOSQUARE * NUMTOSQUARE theresult = "The result is" &Str(theresult)End Sub</AMSCRIPT>
<AMSHOWDIALOG RESULTVARIABLE="NUMTOSQUARE">%theresult%.</AMSHOWDIALOG>
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Custom functions
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.
Here's an example of the same task restructured with a custom function:
<AMVARIABLE NAME="NUMTOSQUARE" VALUE="1" />
<AMVARIABLE NAME="theresult" />
<AMSHOWDIALOG ACTIVITY="input" MESSAGE="Please enter a number you would like squared." RESULTVARIABLE="NUMTOSQUARE" WINDOWTITLE="Please enter a number" ICON="information" />
<AMSCRIPT>Function SquareNumber(thenumber)SquareNumber = thenumber * thenumber End Function</AMSCRIPT>
<AMSHOWDIALOG>The result 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.