Table of contents
TOC
Collapse the table of content
Expand the table of content

Property Set Statement

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Declares the name, arguments, and code that form the body of a Propertyprocedure, which sets a reference to an object.

Syntax

[ Public |Private |Friend ] [ Static ] PropertySetname( [ arglist, ] reference) [ statements ] [ Exit Property ] [ statements ]

End Property The Property Set statement syntax has these parts:

PartDescription
OptionalOptional. Indicates that the argument may or may not be supplied by the caller.
PublicOptional. Indicates that the PropertySet procedure is accessible to all other procedures in allmodules. If used in a module that contains an Option Private statement, the procedure is not available outside theproject.
PrivateOptional. Indicates that the PropertySet procedure is accessible only to other procedures in the module where it is declared.
FriendOptional. Used only in a class module. Indicates that the Property Set procedure is visible throughout theproject, but not visible to a controller of an instance of an object.
StaticOptional. Indicates that the PropertySet procedure's localvariables 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.
nameRequired. Name of the PropertySet procedure; follows standard variable naming conventions, except that the name can be the same as a PropertyGet or Property Let procedure in the same module.
arglistRequired. List of variables representing arguments that are passed to the PropertySet procedure when it is called. Multiple arguments are separated by commas.
referenceRequired. Variable containing the object reference used on the right side of the object reference assignment.
statementsOptional. Any group of statements to be executed within the body of the Property procedure.

The arglist argument has the following syntax and parts: [ Optional ] [ ByVal |ByRef ] [ ParamArray ] varname [ ( ) ] [ Astype ] [ =defaultvalue ]

PartDescription
OptionalOptional. Indicates that an argument is not required. If used, all subsequent arguments in arglist must also be optional and declared using the Optional keyword. Note that it is not possible for the right side of a Property Setexpression to be Optional.
ByValOptional. Indicates that the argument is passed by value.
ByRefOptional. Indicates that the argument is passed by reference. ByRef is the default in Visual Basic.
ParamArrayOptional. Used only as the last argument in arglist to indicate that the final argument is an Optional array of Variant elements. The ParamArray keyword allows you to provide an arbitrary number of arguments. It may not be used with ByVal, ByRef, or Optional.
varnameRequired. Name of the variable representing the argument; follows standard variable naming conventions.
typeOptional. Data type of the argument passed to the procedure; may beByte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported),Date, String (variable length only),Object, Variant, or a specific object type. If the parameter is not Optional, auser-defined type may also be specified.
defaultvalueOptional. Any constant or constant expression. Valid for Optional parameters only. If the type is an Object, an explicit default value can only be Nothing.

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. It is referred to as reference in the preceding syntax. It can't be Optional.

Remarks If not explicitly specified using Public, Private, or Friend, Property procedures are public by default. If Static isn't used, the value of local variables is not preserved between calls. The Friend keyword can only be used in class modules. However, Friend procedures can be accessed by procedures in any module of a project. A Friend procedure doesn't appear in thetype library of its parent class, nor can a Friend procedure be late bound. All executable code must be in procedures. You can't define a PropertySet procedure inside another Property, Sub, or Function procedure. The Exit Property statement causes an immediate exit from a PropertySet procedure. Program execution continues with the statement following the statement that called the PropertySet procedure. Any number of Exit Property statements can appear anywhere in a PropertySet 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 side of an object reference assignment ( Set statement).

Example

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. 
Property Set Pen(P As Object) 
 Set CurrentPen = P ' Assign Pen to object. 
End Property
© 2017 Microsoft