Break Mode

When your program generates a runtime error, a dialog box similar to the one shown in Figure 7.4 is displayed.

The runtime error dialog box.

The runtime error dialog box.

Selecting the Debug option will load the VBA IDE and display the program in Break Mode. While in Break Mode, program execution is paused and can be stepped through one line at a time to closely examine factors such as order of code execution and the current values stored within variables. The line of code that generated the error will be highlighted as shown in Figure 7.5.

The Debug toolbar

Toggle breakpoints

The Debug toolbar

Toggle breakpoints

The VBA IDE in Break Mode.

Step Into

Debug windows

Step Into

The VBA IDE in Break Mode.

Debug windows

To intentionally enter Break Mode, insert a breakpoint at the desired location in the program using the Debug menu item or Debug toolbar (select from the View menu) in the VBA IDE (refer to Figure 7.5). You can also toggle a breakpoint by clicking the left margin of the code window next to the line of code at which you want program execution to pause, or by pressing F9.

Insert break points at locations in code where bugs are suspected or known to exist and then run the program. Break Mode is entered when program execution proceeds to a line of code containing a breakpoint. At this time, you have the option of resetting the program, stepping through the program one line at a time, or continuing normal operation of the program. While in Break Mode, the value currently stored in a variable can be checked by holding the mouse cursor over the name of that variable. Logic errors are often caused by code that assigns the wrong value to a variable. Break Mode can help locate the code that creates these errors.

Another useful debugging method is stepping through code while in Break Mode. Use Step Into on the Debug toolbar, or press F8, to execute one line of code at a time starting from the location of the break. The order of program execution can be verified, and values stored within variables checked as code execution proceeds one line at a time.

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Responses

Post a comment