Description
The Set statement assigns an object reference to a variable or property, or associates a procedure reference with an event.
This statement has the following forms:
Set objectvar = {objectexpression | New classname | Nothing}
Set object.eventname = GetRef(procname)
Parameter | Description |
---|---|
objectvar | (required) Specifies the name of the variable or property Note: objectvar must follow the standard variable naming conventions |
objectexpression | (optional) Specifies an expression consisting of the name of an object, another declared variable of the same object type, or a function or method that returns an object of the same object type |
New | Specifies a keyword used to create a new instance of a class. If objectvar contained a reference to an object, that reference is released when the new one is assigned. The New keyword can only be used to create an instance of a class. |
classname | (optional) Specifies the name of the class being created. A class and its members are defined using the Class statement. |
Nothing | (optional) Discontinues association of objectvar with any specific object or class. Assigning objectvar to Nothing releases all the system and memory resources associated with the previously referenced object when no other variable refers to it. |
object | (required) Specifies the name of the object with which eventname is associated |
eventname | (required) Specifies the name of the event to which the function is to be bound |
procname | (required) Specifies a string containing the name of the Sub or Function being associated with eventname |
Examples
The following example shows the basic use of this statement:
Class Customer
Private m_Name
Public Property Get Name
Name = m_Name
End Property
Public Property Let Name(customerName)
m_Name = customerName
End Property
End Class
Dim custA, custB
' Create an instance of the Customer class,
' and assign it to the custA variable
Set custA = New Customer
' Set a property of the custA object.
custA.Name = "Weyland Group"
' Have the custB variable reference the
' same object as the custA variable
Set custB = custA
' Because the custA and custB variables
' reference the same object, the property's
' value is the same in both
MsgBox(custA.Name)
MsgBox(custB.Name)
Miscellaneous Information
Supported in Version: | 1.0 |
---|