Next, a quick check of the Name property is done to see that it is holding your default
value??”in this case the nonsense value NOG.
The next four lines set all of the properties of the Employee object with real values:
emp.ID = 15
emp.Name = "John Doe"
emp.Title = "Analyst"
emp.PhoneNumber = "8885555555"
CHAPTER 1 n THE MACRO RECORDER AND CODE MODULES 34
Each time you pressed the Enter key, the Property Let method fired for each property and
assigned the value you passed in to the module-level variable for each property. Then you typed
in commands to show that the cEmployee object was indeed storing the values entered previously.
?emp.name
John Doe
?emp.ID
15
?emp.title
Analyst
?emp.phonenumber
8885555555
Each time you pressed the Enter key, the Property Get method fired and retrieved the
value currently stored in the module-level variable for each property.
The final line of code removes the object from memory. Any attempt to write or retrieve
a value after the object is destroyed will result in an error.
set emp = Nothing
When the object is set to Nothing, any code placed in the Class_Terminate method will
run. As previously noted, this is where you will perform any necessary cleanup before the
object is destroyed.
The Class-y Way of Thinking
Our cEmployee class, while extremely simple in content and functionality, does serve the purpose
of showing some of the benefits of writing class-based code.
Let??™s assume for a moment that we had written validation and formatting code into the
Property Lets and Gets of the class, as well as some business rules; or that we had added
methods to export the employee data to a delimited string or set of XML tags for import into
an external system.
Pages:
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61