BASIC Scripts & Custom Functions

Subroutines


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.

 

 

<AMVARIABLE NAME="NUMTOSQUARE">1</AMVARIABLE>

<AMVARIABLE NAME="theresult"></AMVARIABLE>

<AMSHOWDIALOG ACTIVITY="input" RESULTVARIABLE="NUMTOSQUARE">Which number would you like squared?</AMSHOWDIALOG>

<AMSCRIPT>Sub Main

  theresult = NUMTOSQUARE * NUMTOSQUARE

  theresult = &quot;The result is&quot; &amp; Str(theresult)

End Sub</AMSCRIPT>

<AMSHOWDIALOG RESULTVARIABLE="NUMTOSQUARE">The result of the entered number squared is %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">1</AMVARIABLE>

<AMVARIABLE NAME="theresult"></AMVARIABLE>

<AMSHOWDIALOG ACTIVITY="input" RESULTVARIABLE="NUMTOSQUARE" WINDOWTITLE="Please enter a number">Which number would you liked squared?</AMSHOWDIALOG>

<AMSCRIPT>Function SquareNumber(thenumber)

  SquareNumber = thenumber * thenumber

End Function</AMSCRIPT>

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

See Also

BASIC Script Action

Introduction to BASIC scripting

The BASIC Language Grouped by Type

Introduction to Extended Functions

See Also


BASIC Script Action | Introduction to BASIC scripting | The BASIC Language Grouped by Type | Introduction to Extended Functions