Summary

Debugging an application is certainly not the most glamorous part of the development process, but you can't deny the importance of good debugging skills. Developing good debugging skills can save you a significant amount of time, effort, and frustration.

There are three classifications of errors: syntax errors, run-time errors, and logical errors. Syntax errors arise due to code that doesn't adhere to the syntax requirements of the VBA language. Syntax errors can be detected automatically by the compiler before distributing an application. Run-time errors are the most noticeable errors. Run-time errors occur when your application encounters a condition or set of conditions that it was not designed to handle. Run-time errors are best minimized by incorporating defensive programming into your applications. Logical errors can be the most frustrating errors because they have the potential to lurk in your program unnoticed, possibly producing errant or flawed output. Logical errors are also the most difficult to root out in your code. Unlike with syntax or run-time errors, the VBE can't determine the source of logical errors, so you must invoke more troubleshooting skills to find and fix them.

Thankfully the VBE incorporates a number of features and tools to aid the debugging process. Break mode allows you to execute code one line at a time and inspect variables as you go. You can also set Breakpoints, use the Stop statement, or set Watches to enter Break mode at critical junctures in your code. In addition, you can use Debug.Print and MsgBox to display information about your variables as your program runs. Finally, you can use the Locals window to display a wealth of information about all in scope variables while you're in Break mode.

In the next chapter, you'll finally get into the Excel object model, beginning with the Application object. The Application object contains many useful properties and methods that you'll use in nearly every application you develop.

0 0

Post a comment