Help files

Functions

A function in WinAutomation consists of actions grouped together so they can be invoked by a function name.

Functions_Image_2a2.png

To create a new function, click on the New Function button (addfunctionicon.png). Alternatively, you may also press Ctrl+N. Functions can be created, removed, renamed and have their tabs re-ordered freely, with the sole exception of Main, from the Functions pane.

To invoke a function, place a Run Function action anywhere in the Process. When this action is reached, the execution flow will jump to the first action of the invoked function and continue from there. Sooner or later, the actions of the invoked function will all be executed or an Exit Function will be reached. At that point, the execution flow will return at its former position, namely the next action after the invoking Run Function action.

Functions usually perform a specific task and it is considered a good practice to name them in a manner indicative of their purpose. A function name is unique, i.e. two functions cannot share a common name while residing in the same Process.

New Processes, by default, contain only one function, the Main. The Main function is always called when the Process first executes. Other functions may be called by means of the Run Function action, by the Exception Handling mechanism of any action, or as a result of a button press inside a Custom Dialog.

Scope: Variables in a WinAutomation Process are global in the notion that every action can access any variable of the Process from any function.

Go To statements on the other hand, can jump to labels inside their own function only.

Recursion: A function cannot call itself; It can Exit, Run another function or exhaust its actions and return automatically.

Some of the benefits of using functions are:

  • Enhanced readability

  • Code re-use without duplication

  • Modular testing capabilities

Note: Processes created with versions of WinAutomation prior to version 5 will have all their actions moved inside Main when you first edit them.