Microsoft Office 2000/Visual Basic Programmer's Guide   

Property Let Procedures

A Property Let procedure sets the value for a scalar property. The Property Let procedure takes one argument, which is the value that the property is to store. Note that since it sets a value, rather than returning one, the Property Let procedure doesn't have a return value.

The Property Let procedure doesn't do all of the work for you — if you want to store the value that's passed into the Property Let procedure, you have to actually store the value that you pass into the procedure yourself. You can store it in a private module-level variable. For example, the following Property Let procedure sets the LastName property for a hypothetical Customer object:

' Declare private module-level variable to store value.
Private p_strLastName As String

Public Property Let LastName(strLastName As String)
   ' Store value of argument in module-level variable.
   p_strLastName = strLastName
End Property

When you work with the Customer object from code in another module, you can set the LastName property as follows:

Dim cstCust As Customer

Set cstCust = New Customer
cstCust.LastName = "Andrews"

This line of code passes the value "Andrews" to the Property Let LastName procedure. The procedure then assigns this value to the module-level variable p_strLastName.

You don't always have to store a property value in a module-level variable. In some cases, you may use the Property Let procedure to affect some aspect of the application or system. For example, the following Property Let procedure sets the minute portion of the local system time. To do so, it calls the Windows API SetLocalTime function:

Public Property Let Minute(intMinute As Integer)
   ' Retrieve current time so that all values will be current.
   ' Then set minute portion of local time.
   
   GetLocalTime sysSystemTime
   sysSystemTime.wMinute = intMinute
   SetLocalTime sysSystemTime
End Property

There's no point in storing the value of the Minute property in a module-level variable; if you retrieve the property value several minutes later, the stored value will be inaccurate. The following section describes how to retrieve the value of the Minute property by calling the Windows API GetLocalTime function.

This procedure is available in the System class module in System.xls, available in the ODETools\V9\Samples\OPG\Samples\CH10 subfolder on the Office 2000 Developer CD-ROM. To see how the Property procedure works, run the SetLocalSystemTime procedure in the modSystemInfo module in the sample project. This procedure creates a new instance of the System class and sets the Hour, Minute, and Second properties to update the local system time.

For more information about calling the SetLocalTime function and other API functions, see Chapter 10, "The Windows API and Other Dynamic-Link Libraries."