Creating user-defined functions

To create a user-defined function, choose Functions from the Scripts menu on the tool bar. The Functions window will appear. Select the appropriate core for the function script. Click New to create a new function or select a function and click Open to edit an existing function. The script editor will appear, allowing you to write the script for the function.

The name you give the function script in the script editor is the same name that will be used when the function is called. You don’t need to include the parentheses in the name. We also recommend that this name not contain any spaces. If the name is more than one word, substitute underscores (_) for spaces in the name.

The first non-comment line of the function indicates what the function will return. It has the following format:

function returns type variable;

The type parameter indicates the type of value returned by the function. Typically, this is one of the seven standard storage types: boolean, currency, date, integer, long, string or time. You can also use existing global field definitions in your application dictionary to specify the return value type. This is useful if you want to return something such as composite from the function.

The variable parameter indicates the variable that returns the value from the function. This value is returned automatically when the function script finishes. If you don’t specifically set the value of the return variable, it will be returned with the “empty” value for that type. (For example, an integer return value that didn’t have its value set would be returned as 0.)

If you don’t want the function to return any value at all, use the keyword nothing to indicate that the function doesn’t return a value. The first line of the function would be:

function returns nothing;

The parameters for the function follow the first line. The parameters are optional; you can create a function that doesn’t use any parameters. Any parameters for the function are declared and operate the same way that parameters do for procedures. With the exception of the return value, a function script has the same characteristics as a procedure, such as access to all tables in the application dictionary.

Documentation Feedback