Declares the name, arguments, and code that form the body of a Property procedure, which sets a reference to an object.
[Public | Private][Static] Property Set name [(arglist)]
[statements]
[Exit Property]
[statements]End Property
The Property Set statement syntax has these parts:
Part |
Description |
Public |
Indicates that the Property Set procedure is accessible to all other procedures in all modules. If used in a private module (one that contains an Option Private statement), the procedure is not available outside the project. |
Private |
Indicates that the Property Set procedure is accessible only to other procedures in the module where it is declared. |
Static |
Indicates that the Property Set procedure’s local variables are preserved between calls. The Static attribute doesn’t affect variables that are declared outside the Property Set procedure, even if they are used in the procedure. |
name |
Name of the Property Set procedure; follows standard variable naming conventions, except that the name can be the same as a Property Get or Property Let procedure in the same module. |
arglist |
List of variables representing arguments that are passed to the Property Set procedure when it is called. Multiple arguments are separated by commas. The last argument is the object reference used on the right-hand side of an object reference assignment. |
statements |
Any group of statements to be executed within the body of the Property procedure. |
The arglist argument has the following syntax and parts:
[ByVal | ByRef] varname[( )][As type]
Part |
Description |
ByVal |
Indicates that the argument is passed by value. |
ByRef |
Indicates that the argument is passed by reference. |
varname |
Name of the variable representing the argument; follows standard variable naming conventions. |
type |
Data type of the argument passed to the Property Set procedure; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Date, String (variable length only), Object, Variant, a user-defined type, or an object type. |
Note Every Property Set statement must define at least one argument for the procedure it defines. That argument (or the last argument if there is more than one) contains the actual object reference for the property when the procedure defined by the Property Set statement is invoked.
If not explicitly specified using either Public or Private, Property procedures are public by default. If Static is not used, the value of local variables is not preserved between calls.
All executable code must be in procedures. You can’t define a Property Set procedure inside another Property, Sub, or Function procedure.
The Exit Property keywords cause an immediate exit from a Property Set procedure. Program execution continues with the statement following the statement that called the Property Set procedure. Any number of Exit Property statements can appear anywhere in a Property Set procedure.
Like a Function and Property Get procedure, a Property Set procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Function and Property Get procedure, both of which return a value, you can only use a Property Set procedure on the left-hand side of an object reference assignment (Set statement).
Function Statement, Property Get Statement, Property Let Statement, Set Statement, Sub Statement.
This example uses the Property Set statement to define a property procedure that sets a reference to an object.
' The Pen property may be set to different Pen implementations.Set Pen(P As Object) Set CurrentPen = P ' Assign Pen to object.Property