Considering Types of Program Errors

Errors in code can happen at any time in the create/compile/execute sequence. Programmers generally categorize the types of errors that they have to deal with as follows:

1 Compile errors: Any problem that prevents the VBA editor from translating a line of source code to something executable generates a compile error, like the example shown in Figure 12-1. Such errors are usually syntax errors, meaning that you didn't obey the rules of syntax for that statement when typing the code.

1 Logical errors: If your code runs without generating an error message but fails to do what you expected it to do, that's a logical error. In other words, the code can and does run, but the logic of the procedure isn't the right logic for achieving the desired result.

1 Runtime errors: The code compiles okay, but when you run the code, it doesn't work. Instead, it pops a runtime error message onscreen, perhaps looking something like the example shown in Figure 12-3.

Figure 12-3:

A sample runtime error message.

Figure 12-3:

A sample runtime error message.

In the following sections, I look at the tools and techniques for dealing with each type of error, starting with the ubiquitous compile error, which rears its ugly head most often.

0 0

Post a comment