Property Let Statement
Updated: April 2009
Declares, in a Class block, the name, arguments, and code that form the body of a Property procedure that assigns (sets) the value of a property.
[Public | Private] Property Let name ([arglist,] value) [statements] [Exit Property] [statements] End Property
If not explicitly specified using either Public or Private, Property Let procedures are public by default, that is, they are visible to all other procedures in your script. The value of local variables in a Property Let procedure is not preserved between calls to the procedure.
You can't define a Property Let procedure inside any other procedure (e.g. Function or Property Get).
The Exit Property statement causes an immediate exit from a Property Let procedure. Program execution continues with the statement that follows the statement that called the Property Let procedure. Any number of Exit Property statements can appear anywhere in a Property Let procedure.
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) contains the actual value to be assigned to the property when the procedure defined by the Property Let statement is invoked. That argument is referred to as value in the preceding syntax. |
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, you can only use a Property Let procedure on the left side of a property assignment expression.
The following example illustrates the use of the Property Let statement.
Class Customer
Private m_CustomerName
Private m_Address(2)
Private Sub Class_Initialize
m_CustomerName = ""
m_Address(0) = ""
m_Address(1) = ""
End Sub
' CustomerName property.
Public Property Get CustomerName
CustomerName = m_CustomerName
End Property
Public Property Let CustomerName(custname)
m_CustomerName = custname
End Property
' Address property.
Public Property Get Address(index)
Address = m_Address(index)
End Property
Public Property Let Address(index, addr)
m_Address(index) = addr
End Property
End Class
Dim cust
Set cust = New Customer
' Set the object's properties.
cust.CustomerName = "Fabrikam, Inc."
cust.Address(0) = "4567 Main Street"
cust.Address(1) = "Suite 100"
' Get the object's properties.
Dim s
s = s & cust.CustomerName & vbCrLf
s = s & cust.Address(0) & vbCrLf
s = s & cust.Address(1) & vbCrLf
MsgBox (s)
Note: