Property Set Statement |
No
[Public | Private | Friend] [Static] Property Set name _ ([arglist,] reference) [statements] [Exit Property] [statements] End Property
Public
Use: Optional
Type: Keyword
Gives the property scope through all procedures in all modules in the project. If used within a createable class module, the function is also accessible from outside the project. Public, Private, and Friend are mutually exclusive.
Private
Use: Optional
Type: Keyword
Restricts the scope of the property to those procedures in the same module. Public, Private, and Friend are mutually exclusive.
Friend
Use: Optional
Type: Keyword
Only valid within a class module; gives the property scope to all modules within a project, but not to modules outside the project. Public, Private, and Friend are mutually exclusive.
Static
Use: Optional
Type: Keyword
Preserves the value of all private variables declared inside the property between calls to the property.
name
Use: Required
Type: Any
The name of the property.
arglist
Use: Required
A comma-delimited list of variables to be passed to the property as arguments from the calling procedure.
reference
Use: Required
Type: Object
The last (or only) argument in arglist, which is a variable containing the object reference to be assigned to the property.
statements
Use: Optional
Program code to be executed within the property.
arglist uses the following syntax and parts:
[Optional] [ByVal | ByRef] [ParamArray] varname[( )] _ [As type] [= defaultvalue]
Optional
Use: Optional
Type: Keyword
An optional argument is one that need not be supplied when calling the property. However, all arguments following an optional one must also be optional. A ParamArray argument can't be optional.
ByVal
Use: Optional
Type: Keyword
The argument is passed by value; that is, a local copy of the variable is assigned the value of the argument.
ByRef
Use: Optional
Type: Keyword
The argument is passed by reference; that is, the local variable is simply a reference to the argument being passed. All changes made to the local variable are reflected in the calling argument when control returns to the calling procedure. ByRef is the default method of passing variables.
ParamArray
Use: Optional
Type: Keyword
Indicates that the argument is an optional array of variants containing an arbitrary number of elements. It can be used only as the last element of the argument list, and it can't be used with the ByRef, ByVal, or Optional keywords.
varname
Use: Required
Data Type: Any
The name of the local variable containing either the reference or value of the argument.
type
Use: Optional
The data type of the argument.
defaultvalue
Use: Optional
For optional arguments, you can specify a constant default value.
Declares the name, arguments, and code for a procedure that assigns an object reference to a property.
A Property Set statement must contain at least one argument in arglist. If there is more than one argument, it's the last one that contains the object reference to be assigned to the property.
The data type of the last argument in arglist must match both the private data member used to hold the property value and the return value of the corresponding Property Get procedure, if there is one.
Property procedures are Public by default.
In VBA applications, the Option Private Module restricts the scope of procedures defined as public to the project in which they were defined.
The Friend keyword is only valid within class modules. Friend procedures are accessible to all procedures in all modules and classes within a project, but they aren't listed in the type library for that project. Therefore, they can't be accessed from projects or applications outside the defining application.
Properties and procedures defined using the Friend keyword can't be late bound.
The Static keyword only affects private variables declared within the Property Set procedure. If you don't use the Static keyword, the values of local variables are lost between calls.
Unlike other variables and procedures, the name of a Property Set procedure can be repeated within the same module as the name of a Property Get procedure.
The number and data types of the arguments passed to a Property Set statement must match the corresponding Property Get statement. For example:
Public Property Set MyProperty(sVal As String, _ oVal As myObject) Set miMyProperty = oVal End Property Public Property Get MyProperty(sVal As String) As myObject Set MyProperty = miMyProperty End Property
If an Exit Property statement is executed, program execution immediately continues with the statement following the call to the property. Any number of Exit Property statements can appear in a Property Set procedure.
You should protect the values of properties by defining a Private variable to hold the internal property value and control the updating of the property by outside applications via Property Let and Property Get statements, as described in Section 7.233.5 of the entry for the Property Get statement.