Property Let Statement

Named Arguments

No

Syntax

[Public | Private | Friend] [Static] Property Let name _
          ([arglist,] value)
   [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 property procedure 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 within 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: Keyword

The name of the property.


arglist

Use: Required

Data Type: Any

A comma-delimited list of variables to be passed to the property as arguments from the calling procedure.


value

Use: Required

Type: Any

The last (or only) argument in arglist, being a variable containing the value 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

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.

Description

Declares the name, arguments, and code for a procedure which assigns a value to a property.

Rules at a Glance

  • A Property Let statement must contain at least one argument in arglist. If there is more than one argument, it's the last one that contains the value to be assigned to the property.

  • The data type of the last argument in arglist must match both the private data member (at least, it should be defined as Private; see Section 7.234.5) that holds 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 statement 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 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 affects only variables declared within the Property Let procedure. If you don't use the Static keyword, the values of all local variables are lost between calls.

  • Unlike other functions and procedures, the name of the Property Let procedure can be repeated within the same module as the name of the Property Get and Property Set procedures.

  • The number and data types of the arguments passed to a Property Let statement must match the corresponding Property Get statement. For details, see Section 7.233.4 in the entry for Property Get.

  • If an Exit Property statement is executed, program flow continues with the statement following the call to the property. Any number of Exit Property statements can appear in a Property Let procedure.

Programming Tips and Gotchas

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 Property Get Statement.

See Also

Property Get Statement, Property Set Statement, Section 4.1.1
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset