Debug A Procedure With Inserted Break Points

You can insert break points in a procedure to stop execution at the specified line of code. Break points enable you to quickly debug problems with a subroutine or function as well as to determine whether a procedure executes correctly up to the specified location.

You can display the Locals window in the Visual Basic Editor to view the current values of the local variables. When you debug your code, consider docking this window to the bottom of the screen so that you can view the local variables while you debug. After you set a break point, the procedure executes until it reaches the specified break point, and Visual Basic Editor highlights the break point and stops the execution.

The Locals window, which displays in the last opened location, shows the current values of all local variables at each break point. If a variable does not have the

DEBUG A PROCEDURE WITH INSERTED BREAK POINTS

appropriate value when you reach a break point, you know that the coding error occurred prior to the current break point. See Chapter 2 for more information on using the Visual Basic Editor windows.

When your procedure stops at a specified break point, VBA places you in Break mode and stops the execution of the current procedure. You can continue executing your procedure until it encounters another break point or end the procedure. Each time VBA encounters a break point, the values of the local variables update in the Locals window.

You can set a break point for a code statement in the margins of the Code window. The Visual Basic Editor inserts a dark circle next to the code and highlights the line of code based upon the formatting settings you specify. See Chapter 2 for more information on setting the display settings for the Code window.

DEBUG A PROCEDURE WITH INSERTED BREAK POINTS

—n In the Projects window, open the module containing the procedure you want to debug.

■ The Locals window displays in the last viewed location.

—n In the Projects window, open the module containing the procedure you want to debug.

Note: See Chapter 2 for information on opening VBA modules.

L0 Click View O Locals Window.

■ The Locals window displays in the last viewed location.

< Click in the margin next to the line of code to add a break point.

-■ You can add additional break points as needed.

0 0

Post a comment