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 in three ways:

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, which means 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, but when you run the code, it doesn't work. Instead, it pops a runtime error message on-screen, perhaps looking something like the example shown in Figure 12-3.

Figure 12-3:

Sample runtime error message.

Figure 12-3:

Sample runtime error message.

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

Was this article helpful?

0 0

Post a comment