LOTUSSCRIPT LANGUAGE


Scope of declarations
Scope is the context in which a variable, procedure, class, or type is declared. Scope affects the accessibility of an item's value outside that context. For example, variables declared within a procedure are typically not available outside of the scope of that procedure.

LotusScript recognizes three kinds of scope:


Name conflicts and shadowing

Two variables or procedures with the same name cannot be declared in the same scope. The result is a name conflict. The compiler reports an error when it encounters a name conflict in a script.

Variables or procedures declared in different scopes can have the same name. LotusScript interprets the name as referring to the variable or procedure declared in the innermost scope that is visible where the reference is used.

A variable or procedure of the same name declared at a scope outside of this innermost visible scope is not accessible. This effect is called shadowing: the outer declaration(s) of the name are shadowed, or made invisible, by the inner declaration.

Module scope

A variable is declared in module scope if the declaration is outside of any procedure, class, or type definition in the module. The variable name has a meaning as long as the module is loaded.

The variable name is visible anywhere within the module and has the meaning specified in the declaration, except within a procedure, type, or class where the same variable name is also declared.

The variable is Private by default and can be referred to only within the module that defines it. A variable can be referred to in other modules only if it is declared as Public and the other modules access the defining module with the Use statement.

The following situations result in a name conflict across modules:


The following situations result in a name conflict within a module:
Procedure scope

A variable is declared in procedure scope if it is declared within the definition of a function, a sub, or a property. Only inside the procedure does the variable name have the meaning specified in the declaration. The variable name is visible anywhere within the procedure.

Ordinarily, the variable is created and initialized when the procedure is invoked, and deleted when the procedure exits. This behavior can be modified with the Static keyword:


The following situations result in a name conflict within a procedure:
Type or class scope

A variable is declared in type or class scope if it is declared within the definition of a type or a class (for classes, it must additionally be declared outside the definition of a procedure). The variable is called a member variable of the type or class.


The visibility of a type member variable (which is always Public) and of a Public class member variable depends, for any particular type or object, on the declaration of the instance variable that refers to that instance:
The following situation results in a name conflict within a type:
The following situation results in a name conflict within a class:
See Also