Microsoft Office Tutorials and References
In Depth Information
Chapter 6: Debugging Your Code
Chapter 6: Debugging Your Code
In This Chapter
Identifying types of errors
Figuring out how to solve compiler errors
Trapping and fixing runtime errors
Digging out logical errors
Instant gratification is rare in the world of programming. Nobody writes
perfect code every time. Usually, coding takes some trial and error: You
write a little code, test it, find and fix any bugs (errors), write a little more,
test a little more, and so on until the code is fully debugged (free of errors)
and runs smoothly every time. With the help of some debugging tools built
into Visual Basic for Applications (VBA) and Visual Basic Editor, you usually
can track down, and fix, any problems that are causing your code to fail.
Recognizing Types of Program Errors
Many things can go wrong in the process of writing code, especially for a
beginner. Being able to identify what type of error you’re dealing with is
helpful. The three types of errors that all programmers have to contend
with are
Compiler errors: A problem with the code prevents the procedure from
running at all. Messages alerting you to compiler errors often appear right
in the Code window — such as when you type a faulty VBA statement and
press Enter before you catch the goof.
Runtime errors: The code compiles without error but fails to run
properly in practice, often because of a problem in the environment. If a
procedure assumes that a certain form is already open in Form view, for
example, but that form isn’t open, the code crashes — stops running —
before the procedure completes its task.
Logical errors: The code compiles and runs without displaying any
error messages, but the code doesn’t do what it’s supposed to do.
Fortunately, Visual Basic Editor contains tools that help you track down,
catch, and fix all these errors. We start with compiler errors because you
have to fix them before the code can do anything at all.
Search JabSto ::

Custom Search