Let??™s run
the code in the Immediate window.
1. Open the Immediate window from the VBE by choosing View ?¤ Immediate Window or
by pressing Ctrl+G.
2. Type in the following: ?BirthYear(30,True).
3. Press Enter to see the result.
nNote In the Immediate window, when you precede a command or variable name with the ? character, the
result of the command (or contents of the variable) will be output to the Immediate window. Otherwise, the
command will just run, unless there are errors.
We passed in 30 as the Age parameter (you didn??™t think I??™d put my real age in there, did
you?) and set the flag to True, indicating that the birthday had passed for this year. This code
was run in the year 2007, so the result I would expect to see is 1977??”but that??™s not what we see
in Figure 7-5, is it?
Figure 7-5. Unexpected result in Immediate window
Let??™s check our variables and make sure they??™re holding correct values by inserting a few
message boxes. You can create message boxes by calling the MsgBox function. As shown in Figure
7-6, the MsgBox function takes a few arguments, but since we??™re not presenting these to a
user at this time, we??™ll just pass in the first argument, the prompt or message.
Figure 7-6. The MsgBox function??™s argument list
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 255
1. In the BirthYear function, add the following code above the If...End If statement:
MsgBox "Current Year: " & CStr(iCurrYear)
MsgBox "Birth Year before If: " & CStr(iReturn)
2.
Pages:
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245