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

Writing a Property Procedure

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

A Property procedure is a series of Visual Basicstatements that allow a programmer to create and manipulate custom properties.

  • Property procedures can be used to create read-only properties forforms, standard modules, and class modules.

  • Property procedures should be used instead of Public variables in code that must be executed when the property value is set.

  • Unlike Public variables, Property procedures can have Help strings assigned to them in theObject Browser.

When you create a Property procedure, it becomes a property of themodule containing the procedure. Visual Basic provides the following three types of Property procedures:

Property LetA procedure that sets the value of a property.
Property GetA procedure that returns the value a property.
Property SetA procedure that sets a reference to an object.

The syntax for declaring a Property procedure is: [ Public |Private ] [ Static ] Property { Get |Let |Set } propertyname__ [( _arguments )] [ Astype ] statementsEnd PropertyProperty procedures are usually used in pairs: Property Let with Property Get and Property Set with Property Get. Declaring a Property Get procedure alone is like declaring a read-only property. Using all three Property procedure types together is only useful for Variant variables, since only a Variant can contain either an object or other data type information. Property Set is intended for use with objects; Property Let isn't. The required arguments in Property procedure declarations are shown in the following table:

ProcedureDeclaration Syntax
Property GetProperty Getpropname (1, …, n ) Astype
Property LetProperty Letpropname (1, …,,,, n, n +1)
Property SetProperty Setpropname (1, …, n, n +1)

The first argument through the next to last argument (1, …, n ) must share the same names and data types in all Property procedures with the same name. A Property Get procedure declaration takes one less argument than the related Property Let and Property Set declarations. The data type of the Property Get procedure must be the same as the data type as the data type of the last argument ( n +1) in the related Property Let and Property Set declarations. For example, if you declare the following Property Let procedure, the Property Get declaration must use arguments with the same name and data type as the arguments in the Property Let procedure.

Property Let Names(intX As Integer, intY As Integer, varZ As Variant) 
 ' Statement here. 
End Property 

Property Get Names(intX As Integer, intY As Integer) As Variant 
 ' Statement here. 
End Property 

The data type of the final argument in a Property Set declaration must be either anobject type or a Variant.

© 2017 Microsoft