BASIC Scripts & Custom Functions

Overview

AutoMate'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'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 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 BASIC Scripting Language is that an unlimited number of customized AutoMate oriented commands can be added to the language to make life (and automation) easier for you.

AutoMate'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. An example of this type of usage is shown below.

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

 

 

<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" &amp;Str(theresult)

End Sub</AMSCRIPT>

<AMSHOWDIALOG RESULTVARIABLE="NUMTOSQUARE">%theresult%.</AMSHOWDIALOG>

 

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.

An example of the same task restructured with a custom function is shown below:

 

<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.