Property Get/Set statements (LotusScript® Language)

Define a property. A property is a named pair of Get and Set procedures that can be used as if they were a single variable.

Syntax

[ Static ] [ Public | Private ] Property { Get | Set } propertyName [ ( [ paramList ] ) ] [ As type ]

[ statements ]

End Property

Elements

Static

Optional. Specifies that the values of a Static property's variables are saved between calls to the property.

Public | Private

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

A property in module scope is Private by default. A property in class scope is Public by default.

The Property Get and Property Set definitions for a property must use the same Public or Private setting.

Get | Set

Specifies which operation the procedure performs. A Property Get procedure retrieves the value of the property. A Property Set procedure assigns a value to the property.

propertyName

The name of the property. This name can have a data type suffix character appended to declare the data type of the value passed to and returned by the property.

paramList

Optional. A comma-separated list of declarations indicating the parameters to be passed to this property in Get and Set operations. The Get and Set operations must have the same number of arguments.

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.

type

Optional. The data type of values passed to and returned by the property.

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

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

If no type is specified and the property name has no data type suffix character appended, the property's value is either of data type Variant or of the data type specified by a Deftype statement.

The types in the Property Get and Property Set definitions must be the same.

statements

Statements to retrieve or assign a property value.

Usage

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).

A property usually consists of two procedures with the same name: a Property Get and a Property Set. However, you are not required to provide both.

A property member of a class cannot be declared Static. That is, a Property Get or Property Set statement within a class definition cannot begin with Static.

Using Property Get

A Property Get procedure is like a function. For example:

' These statements assign the value of saveInt to x
Dim saveInt As Integer
Property Get pInt As Integer
   pInt% = saveInt%
End Property
x = pInt%

Or:

' These statements assign the value of saveInt plus 
' increment to x
Dim saveInt As Integer
Property Get pInt (increment As Integer) As Integer
   pInt% = saveInt% + increment%
End Property
x = pInt%(1%)

Using Property Set

A Property Set procedure is the reverse of a Property Get procedure. On entry into a Property Set procedure, an implicitly declared variable whose name and data type are the same as those of the Property Set procedure contains a value to be used inside the Property Set procedure. Inside the Property Set procedure, use the value of the variable instead of assigning a value to it.

Call a Property Set procedure by using its name on the left side of an assignment statement. The value following the statement is used by the Property Set procedure. For example:

' These statements assign the value of x to SaveInt
Dim SaveInt As Integer
Property Set pInt As Integer
   saveInt% = pInt%
End Property
pInt% = x

Or:

' These statements assign the value of x + increment
' to SaveInt
Dim SaveInt As Integer
Property Set pInt (increment As Integer) As Integer
   saveInt% = pInt% + increment%
End Property
pInt%(1%) = x

Referencing a property that returns an array, list, or collection

If a Get operation returns an array, list, or collection, a reference to the property can contain subscripts according to the following rules:

  • If the property has parameters, the first parenthesized list following the reference must be the argument list. A second parenthesized list is treated as a subscript list. For example, p1(1,2)(3) is a reference to a property p1 that has two parameters and returns a container.
  • If the property has no parameters and the return type is a variant or collection object, a single parenthesized list following the reference is treated as a subscript list. For example, p1(1) is a reference to a property p1 that either contains one parameter or contains no parameters but is a container.
  • If the property has no parameters and the return type is not a variant or collection object, any parenthesized list following the reference is an error, except that a single empty list is allowed. For example, p1() is a reference to a property p1 that contains no parameters and may or may not be a container; if p1 is a container, the reference is to the entire container.

In a Set operation, the property reference cannot be subscripted. A parenthesized list following the reference must be the argument list. For example, p1(1) is a reference to a property p1 with one parameter; p1(1,2)(3) or p1()(3) is illegal in a Set operation.

Passing a property to a function

A LotusScript® property (a property defined by Property Get or Property Set) can be passed to a function by value only, not by reference.

Example