• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Debugging

The process of finding and correcting errors in code is called debugging. There are several types of errors that can occur in code. The first is a syntaxerror. Syntax errors occur when you misspell a word or don't follow the proper word sequence when writing a VBA statement or series of statements. An If statement without the word Then at the end is an example of incorrect word sequence. The Editor has a feature called Auto Syntax Check that checks a line of code for syntax errors when you move off the line. If an error is detected, it's displayed in a message box, and the Editor applies a red color to the line of code containing the error. Then it's up to you to correct the error.

The second type of error is a runtime error. As the name suggests, runtime errors occur when the code is running. Even if the syntax is correct, the code may be attempting to perform a task that's impossible, such as saving a file to a folder that doesn't exist. When a runtime error occurs, the code stops running, and a message box displays the nature of the error (see Figure 30.11). This message box gives you the option of stopping the code from running with an End button or viewing the line of code causing the error with the Debug button.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint