Property Let Statement

Description

Declares the name, arguments, and code that form the body of a Property Let procedure, which assigns a value to a property.

Syntax

[Public | Private][Static] Property Let name [(arglist)]
[statements]
[Exit Property]
[statements]
End Property

The Property Let statement syntax has these parts:

Part

Description

Public

Indicates that the Property Let 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 Let procedure is accessible only to other procedures in the module where it is declared.

Static

Indicates that the Property Let procedure's local variables are preserved between calls. The Static attribute doesn't affect variables that are declared outside the Property Let procedure, even if they are used in the procedure.

name

Name of the Property Let procedure; follows standard variable naming conventions, except that the name can be the same as a Property Get or Property Set procedure in the same module.

arglist

List of variables representing arguments that are passed to the Property Let procedure when it is called. Multiple variables are separated by commas. The last argument is the value assigned to the property on the right-hand side of an expression.

statements

Any group of statements to be executed within the body of the Property Let 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 Let procedure; may be Boolean, Integer, Long, Currency, Single, Double, Date, String (variable length only), Object, Variant, a user-defined type, or an object type.


Note

Every Property Let statement must define at least one argument for the procedure it defines. That argument (or the last argument if there is more than one) will contain the actual value to be assigned to the property when the procedure defined by the Property Let statement is invoked.

Remarks

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 Let procedure inside another Sub, Function, or Property procedure.

The Exit Property keywords cause an immediate exit from a Property Let procedure. Program execution continues with the statement following the statement that called the Property Let procedure. Any number of Exit Property statements can appear anywhere in a Property Let procedure.

Like a Function and Property Get procedure, a Property Let 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, a Property Let procedure can only be used on the left side of a property assignment expression or Let statement.

See Also

Function Statement, Let Statement, Property Get Statement, Property Set Statement, Sub Statement.

Example

This example uses the Property Let statement to define a procedure that assigns a value to a property that identifies the pen color for a drawing package.


Dim CurrentColor As Integer
Const BLACK = 0, RED = 1, GREEN = 2, BLUE = 3

' Sets the pen color property for a Drawing package.
' The module level variable 'CurrentColor' is set to
' a numeric value that identifies the color used for drawing.
Property Let PenColor(ColorName as String)
    Select Case ColorName    ' Check color name string.
        Case "Red"
            CurrentColor = RED    ' Assign value for Red.
        Case "Green"
            CurrentColor = GREEN    ' Assign value for Green.
        Case "Blue"
            CurrentColor = BLUE    ' Assign value for Blue.
        Case Else
            CurrentColor = BLACK    ' Assign default value.
    End Select
End Property

' The following line sets the PenColor property for a drawing package
' by calling the Property Let procedure.

PenColor() = "Red"