Sub New (LotusScript® Language)

A user-defined sub that LotusScript® executes when you create an object of the class for which the New sub is defined.

Syntax

Sub New [ ( [ argList ] ) ] [ , baseClass ( [ baseArgList ] ) ]

[ statements ]

End Sub

Elements

argList

Optional. A comma-separated list of parameter declarations for the New sub, enclosed in parentheses. Use the following syntax for each parameter declaration:

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

ByVal means that paramName is passed by value: that is, the value assigned to paramName is a copy of the value specified in the sub call, rather than a reference to the original value.

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.

As dataType specifies the variable data type. You can omit this clause and use a data type suffix character 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 character (and isn't covered by an existing Deftype statement), its data type is Variant.

If the New sub for the derived class has no arguments, and the New sub for the base class has no arguments, omit (argList) and baseClass (baseArgList).

baseClass ( [ baseArgList ] )

Optional. The baseClass is the name of the class from which the derived class is derived. This name must match the baseClass name in the Class statement for the derived class.

The baseArgList is a comma-separated list of arguments for the sub New of the base class. Note that these are actual arguments, not parameter declarations. This syntax enables a call of the New sub for the derived class to furnish actual arguments to the call of the New sub for the base class.

Include this syntax in the New sub only if all of these conditions are true:

  • The class being defined is a derived class.
  • The New sub for the base class of this derived class requires arguments.

    Note that these arguments must be furnished to the New sub for the base class through the call of the New sub for the derived class.

  • The argument list for the sub New of the base class does not match the argument list for the sub New of the derived class in number and data type of arguments; or you want to pass different arguments to the base class sub New than those passed to the derived class sub New.

When the class being defined is a derived class, each call of the New sub for the derived class generates a call of the New sub for the base class. If that base class is itself a derived class of another base class, another call is generated, and so on.

Usage

In the definition for a user-defined class, you can include a definition for the constructor sub, named New. If the definition exists, LotusScript® calls this sub whenever it creates an object from that class. LotusScript® calls the sub immediately after creating the object.

Example