Using the Locals Window and the Call Stack Dialog

If you want to keep an eye on all the declared variables and their current values during the execution of a VBA procedure, be sure to choose View | Locals Window before you run the procedure. While in break mode, Visual Basic will display a list of variables and their corresponding values in the Locals window (see Figure 9-12).

Figure 9-12: The Locals window displays the current values of all the declared variables in the current VBA procedure.

The Locals window contains three columns: Expression, Value, and Type.

The Expression column displays the names of variables that are declared in the current procedure. The first row displays the name of the module preceded by the plus sign. When you click the plus sign, you can check if any variables have been declared at the module level. Here the class module will show the system variable Me. In the Locals window, global variables and variables used by other projects aren't displayed.

The second column, Value, shows the current variable values. In this column, you can change the value of a variable by clicking on it and typing the new value. After changing the value, press Enter to register the change. You can also press Tab, Shift+Tab, up or down arrow, or click anywhere within the Locals window after you've changed the variable value.

Type, the third column, displays the type of each declared variable.

To observe the variable values in the Locals window, do the following hands-on.

Introduction to Access 2003 VBA Programming

©Hands-On 9-3: Using the Locals Window

1. Choose View | Locals Window.

2. Click anywhere inside the WhatDate procedure and press F8. By pressing F8 you placed the procedure in break mode. The Locals window displays the name of the current module, the local variables, and their beginning values.

3. Press F8 a few more times while keeping an eye on the Locals window.

4. Press F5 to continue running the procedure.

The Locals window also contains a button with an ellipsis (...). This button opens the Call Stack dialog box (see Figure 9-13), which displays a list of all active procedure calls. An active procedure call is the procedure that is started but not completed. You can also activate the Call Stack dialog box by choosing View | Call Stack. This option is only available in break mode.

Figure 9-13: The Call Stack dialog box displays a list of procedures that are started but not completed.

The Call Stack dialog box is especially helpful for tracing nested procedures. Recall that a nested procedure is a procedure that is being called from within another procedure. If a procedure calls another, the name of the called procedure is automatically added to the Calls list in the Call Stack dialog box. When Visual Basic has finished executing the statements of the called procedure, the procedure name is automatically removed from the Call Stack dialog box. You can use the Show button in the Call Stack dialog box to display the statement that calls the next procedure listed in the Call Stack dialog box.

Part I

0 0

Post a comment