Using the cEmployee Class
We can test our cEmployee class using the Immediate window in the VBE:
1. Open the Immediate window by choosing View ?¤ Immediate Window or by pressing
the Ctrl+G key combination.
2. In the Immediate window, type - Set emp = New cEmployee, and press Enter.
3. Type - ?emp.Name and press Enter.
Your screen should look like Figure 1-30.
Figure 1-30. Instantiating the cEmployee object in the Immediate window. Property values have
not been set yet.
CHAPTER 1 n THE MACRO RECORDER AND CODE MODULES 33
We??™ve returned our nonsense value from the class initialization code. Now let??™s assign
values to our properties. Type the following commands into the Immediate window, pressing
Enter after each. The first group of commands will set the cEmployee object??™s properties and
the second will retrieve and display them.
emp.ID = 15
emp.Name = "John Doe"
emp.Title = "Analyst"
emp.PhoneNumber = "8885555555"
?emp.name
?emp.ID
?emp.title
?emp.phonenumber
set emp = Nothing
Your Immediate window should look like Figure 1-31.
Figure 1-31. cEmployee object with property values set and returned
Let??™s take a look at what??™s going on here. The first line of code instantiates (or creates) the
employee object:
Set emp = New cEmployee
When that object is created, the Class_Initialize method fires and the default values are
set. As mentioned earlier, this is where you would set up any activities or objects your class
needs to have in place.
Pages:
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60