When Should You Debug Your Code

There are several schools of thought you can follow when deciding when to debug your VBA code. You could debug as you write, testing every few lines. This could be quite time-consuming. You'd have to run your code every few lines (possibly with incomplete procedures) and make heavy use of the tools in this section such as the Immediate window and Watch statements. The advantage to this method is that you'll always know the value of your variables and the likelihood of making a mistake is reduced. The alternative to this method is to write all of the code in your application and then debug your code. This method allows you to write entire procedures or even your entire application's code without debugging. This is a tempting method as it doesn't require you to stop your productive code typing to debug your application. However, you can easily end up with numerous errors in your code, some of which might require you to make major changes to your code as you discover them.

The best method of debugging falls somewhere between these two options. You should definitely debug at the end of each procedure. This allows you to be confident that each procedure produces the appropriate and expected values. Unless you're writing incredibly long procedures, this method should be sufficient to ensure you're not writing code with too many errors.

0 0

Post a comment