Defining functions

When you define a function, you provide the function's signature and the set of statements that are to be executed when the application calls the function.

The syntax for defining a function is:

[ Static ] [ Public | Private ] Function functionName [ ( parameters ) ] [ As dataType ]

statements

Element

Description

Static

Declares variables defined within the function to be static by default. Static variables retain their values (rather than going out of existence) between calls to the function while the module in which it is defined remains loaded.

Public, Private

When you declare a function at module level, Public lets the application refer to the function outside the module in which the function is defined, as long as that module is loaded. Private means that the function is available only within the module in which it is defined. When you declare a function inside the definition of a user-defined class, Public means that the function is available outside the class definition. Private means that the function is only available within the class definition. By default, functions defined at module level are Private, and functions defined within a class are Public.

functionName

The name of the function, which can end in a LotusScript® data type suffixes (%, &, !, #, @, and $). These determine the data type of the function's return value. You can append a data type suffix to a function name when you declare the function only if you do not include the As dataType clause in the declaration.

parameterList

A comma-delimited list of the function's formal parameters (if any), enclosed in parentheses. (The list can be empty.) This list declares the variables for which the function expects to be passed values when it is called. Each member of the list has the following form:

[ByVal] paramName [() | List] [As dataType]

ByVal means that paramName is passed by value; that is, the value assigned to paramName is a local copy of a value in memory rather than a pointer to that value. ByVal is optional.

paramName() is an array variable.

List identifies paramName as a list variable; otherwise, paramName can be a variable of any of the other data types that LotusScript® supports. You can't pass an array, a list, an object reference, or a user-defined data type structure by value.

As dataType specifies the variable's data type. You can omit this clause and use a data type suffix to declare the variable as one of the scalar data types. If you omit this clause and paramName doesn't end in a data type suffix (and isn't covered by an existing Deftype statement), its data type is Variant.

As dataType

Specifies the data type of the function's return value. A function can return a scalar value, a Variant, or an object reference. If you include this clause, functionName cannot end in a data type suffix. If you omit this clause and functionName doesn't end in a data type suffix (and isn't covered by an existing Deftype statement), the function's return value is Variant.

In releases of LotusScript® before 4.0, there were situations where it was required to declare functions before they were referenced. In LotusScript® 4.0, this is no longer needed and forward declarations of LotusScript® functions are accepted and ignored.

The syntax for declaring a function is:

Declare [ Static ] [ Public | Private ] Function functionName [ ( parameterList ) ] [ As dataType ]