Using Functions / Extended Functions

In computer programming, a function is predefined code which can generate various kinds of values depending on certain input from the user. Most programming languages such as VBScript come with a pre-written, built-in range of functions that perform various procedures or routines. Functions can be used as an expression in any task step, thus, adding more intelligence to a task and further broadening the functionality of Automate. Additionally, AutoMate contains an extensive collection of additional functions that increase the functionality of the AutoMate Scripting Engine which are called AutoMate Extended Functions.

Function Syntax

Most functions require other parameters in order to properly complete a procedure or routine. The general format of a function is its name followed by any arguments contained in between parenthesis:

FunctionName (arguments)

An argument (sometimes referred to as parameters) is a value sent to the function when it is called upon. By passing an argument to a function, the function is given information to work on.

Certain functions may not need arguments to properly perform its duty. For example, the Date() function returns the current system date and the Now() function returns the current date along with the time. These functions requires no arguments or parameters in which they need to perform any procedures on, therefore the proper syntax are simply the functions themselves, with nothing entered in between the parenthesis. For instance, if this was entered:


The returned result would be the current date value such as 1/1/2010.

An example of a function which requires arguments is the Len() function, which returns the number of characters in a string. The syntax for this function is Len(“string”) which requires a string to be entered inside the parenthesis in which it will perform calculations on. For example, if this was entered:


The returned value would be 5.

Another example is the AutoMate extended function, ExtractFileName(), which requires a path and filename in between the parenthesis in which it will extract the file name from. So, if the following was entered:


The returned value would be filename.txt.

An example of a function requiring more elaborate arguments is the Left() function, which returns a specified number of characters from the left side of a string. The syntax for this function is Left(“string”, length) which requires a valid string followed by the amount of characters to return inside the parenthesis. If the following was entered:

Left("AutoMate", 4)

The return value would be Auto.

Another example is the InsStr() function which returns the position of the first occurrence of one string within another. The search begins at the first character of the string. The syntax for this function is InStr(“string1”,“String2”). So, if the following was entered:


The return value would be 5 signifying that the letter “o” is the fifth character in the word “Hello”.

NOTE: Sample syntax for each function and AutoMate extended function can be found in the AutoMate Help document.

Using Functions in Task Steps

Built-in VBScript functions along with AutoMate extended functions can be used to return data inside any action parameter in of a task that accepts expressions by surrounding the function with percent signs. The percent signs tell AutoMate that the contents in between the percent signs should not be taken literally, but used as an expression instead. For example, the Len() function can be used with a single ‘Message Box’ action by simply entering %Len(“Hello”)% in the 'Message Box  action's General tab properties under the Message to display parameter (as shown below).

When this task runs, the Len() function will perform its procedure (which returns the number of characters in a string) and return the results in a message dialog, as illustrated below.

Expressions such as variables, constants or other functions can be used as arguments or parameters entered inside the parenthesis of a function. In such cases, the specified expression needs to be entered by itself (omitting any percent signs, quotes or other characters). For example, assume that a variable named theFile is populated with the string value c:\foldername\filename.txt. In order to extract only the filename from this string and view the results in a message dialog, the proper syntax to enter in a ‘Message Box’ step would be %ExtractFileName(theFile)% as shown below.

During task execution, a message dialog will display the properly extracted filename as shown below.


See Also

Introduction to AutoMate Scripting

Introduction to Functions

Introduction to Extended Functions

The BASIC Language Grouped by Type

More on Operators

Order of Precedence