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 AWE. Additionally, AWE contains an extensive collection of additional functions that increase the functionality of the AWE Scripting Engine which are called AWE extended functions.
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 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. A function without arguments must include an empty set of parentheses (). 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 the functions themselves, with nothing entered between the parenthesis. For instance, if this was entered:
Date()
The returned result would be the current date value such as 1/1/2010.
An example of a function that 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 parentheses in which it will perform calculations. For example, if this was entered:
Len(“Hello”)
The returned value would be 5.
Another example is the AWE extended function, ExtractFileName(), which requires a path and filename between the parentheses from which it will extract the file name. So, if the following was entered:
ExtractFileName("c:\foldername\filename.txt")
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 parentheses. 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:
InStr("Hello","o")
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 AWE extended function can be found in the AWE Help document.
Built-in VBScript functions along with AWE extended functions can be used to return data inside any action parameter of a task that accepts expressions by surrounding the function with percent signs. The percent signs tell AWE that the contents between the percent signs should not be taken literally, but used as an expression instead.
Expressions such as variables, constants, or other functions can be used as arguments or parameters entered inside the parentheses of a function. In such cases, the specified expression needs to be entered by itself (omitting any percent signs, quotes or other characters).