Function statement (LotusScript® Language)

Defines a function.


[ Static ] [ Public | Private ] Function functionName [ ( [ paramList ] ) ] [ As returnType ]

[ statements ]

End Function



Optional. Specifies that the values of the function's local variables are saved between calls to the function.

Public | Private

Optional. Public specifies that the function is visible outside the scope (module or class) where the function is defined, as long as that remains loaded. Private specifies that the function is visible only within the current scope.

A function in module scope is Private by default; a function in class scope is Public by default.


The name of the function. This name can have a data type suffix character appended, to declare the type of the function's return value.


Optional. A comma-separated list of declarations indicating the parameters to be passed to this function in function calls.

The syntax for each parameter declaration is:

[ ByVal ] parameter [ ( ) | List ] [ As type ]

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

parameter () is an array variable. parameter List identifies parameter as a list variable. Otherwise, parameter can be a variable of any of the other data types that LotusScript® supports.

As dataType specifies the variable's data type. You can omit this clause and append a data type suffix character to parameter to declare the variable as one of the scalar data types. If you omit this clause and parameter has no data type suffix character appended (and isn't covered by an existing Deftype statement), its data type is Variant.

Enclose the entire list of parameter declarations in parentheses.


Optional. The data type of the value returned by the function.

returnType can be any of the scalar data types, or Variant, or a class name.

If As returnType is not specified, the function name's data type suffix character determines the return value's type. Do not specify both a returnType and a data type suffix character; LotusScript® treats that as an error.

If you omit returnType and the function name has no data type suffix character appended, the function returns a value either of data type Variant or of the data type specified by a Deftype statement.


The Public keyword cannot be used in a product object script or %Include file in a product object script, except to declare class members. You must put such Public declarations in (Globals).

Arrays, lists, type instances, and objects can't be passed by value as arguments. They must be passed by reference.

To return a value from a function, assign a value to functionName within the body of the function definition (see the example).

If you assign an array to functionName, you cannot refer to an element of functionName within the body of the function; such a reference will be taken as a recursive call of the function. To refer to an element of functionName, assign functionName to a variant variable and index the element there.

A function returns a value; a sub does not. To use the value returned by a function, put the function call anywhere in an expression where a value of the data type returned by the function is legal.

You don't have to use the value returned by a function defined by the Function statement. (The value returned by a built-in function must be used.) To call a function without using the return value, use the Call statement.

A function definition cannot contain another function or sub definition, or a property definition.

A function member of a class cannot be declared Static.

You can exit a function using an Exit Function statement.

Note: If you're using a 32-bit version of Windows, an integer has four bytes; use the short integer (two bytes) to correspond to the LotusScript® Integer when passing data to LotusScript®. This note applies to Windows platforms only.