SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 255 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

Return to Excel.
2. Run the AddSalesTotal macro.
3. Click OK when the error message appears, and the code will go into break mode.
4. Press F8 once to step to the next line of code. The execution point will move into the
Exit_Function section.
5. Hold your mouse pointer over the currReturn variable to check its value. As shown in
Figure 7-44, it has a 0 value.
Figure 7-44. Checking the value of currReturn
6. Press F5 to let the code run to finish.
Since our loop never finished running, currReturn was never assigned a value. We have a
couple of choices on how to handle this. We can show no total in case of an error, or we can
show the total of the numeric values.
To show a total and get the loop to finish running, we need to modify the behavior of our
Resume statement. The Resume statement has three forms, as shown in Table 7-4.
Table 7-4. The Resume Statement
Statement Description
Resume Resumes code execution with the statement that caused the error. If the error was
not handled, it becomes fatal.
Resume Next Resumes code execution with the statement following the statement that triggered
the error.
Resume Line Resumes code execution at a line label or number within the procedure containing
the error handler.
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 283
Our type mismatch error occurs in our loop, and in order to populate currReturn with a
value, we??™ll need to complete the loop.
1. Remove the breakpoint.
2. In the GetSalesTotal function error handler, change the Resume statement to read as
follows:
Resume Next
3.


Pages:
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267