Microsoft Knowledge Base
XL: Watch Pane Does Not Use Procedure Call Context
Last reviewed: September 13, 1996
Article ID: Q106498
The information in this article applies to:
- Microsoft Excel for Windows, version 5.0
- Microsoft Excel for the Macintosh, version 5.0
- Microsoft Excel for Windows 95, version 7.0
SYMPTOMS
When you use the Debug window in the Microsoft Visual Basic Programming System, Applications Edition, the Watch pane may not display the watch expression value in the context of the selected procedure call.
CAUSE
When you run a procedure in the Immediate pane as part of the debugging process for your macro, it will be added to the list of procedure calls in the Calls dialog box. This functionality helps you trace the operation of your code. However, if you select a procedure in the Calls dialog box that is listed more than once and choose Show, the current value of your watch expression does not change to the context of the selected procedure.
For example, if your watch expression is a variable, and you run a procedure in the Immediate pane multiple times, and you change the value of the variable each time, the Calls dialog box cannot be used to trace the different values of the variable. The value of the variable in the Watch pane is the value at the last running of the procedure, regardless of the instance of the procedure call selected in the Calls dialog box.
Steps to Reproduce Behavior
- Insert a new Visual Basic module in a workbook by choosing Macro from the Insert menu and choosing Module.
In the new module, type the following code:
'Calls DoubleNum function
Sub Initial() DoubleNum(2) End Sub 'Multiply initial value by 2 Function DoubleNum(Arg1 As Integer) DoubleNum = Arg1*2 ' STOP value to bring up Debug window STOP End Function
- From the Tools menu, choose Add Watch and in the Expression box, type "Arg1" (without the quotation marks).
- In the Procedure box of the Add Watch dialog box, select DoubleNum and in the Module box, select the name of the module inserted in step 1. Under Watch Type, select the Watch Expression button and choose OK.
- From the Run menu, choose Start. If the Macro dialog box appears, select Initial from the Macro Name/Reference list and choose Run.
When the Debug dialog box appears, select the Immediate tab and in the Immediate pane, type the following
DoubleNum(5)
and press Enter.
- Click the button to the right of the Procedure box to display the Calls dialog box. From the Workbook.Module.Procedure list, select the first Book1.Module1.DoubleNum listed (there are two of these lines listed in the Calls dialog box) and choose Show.
- From the Debug Window, select the Watch tab.
Note that the value displayed for Arg1 is 5, even though you selected the first call to the DoubleNum function (which should have an Arg1 value of 2) in the Calls dialog box.
NOTE: Microsoft Visual Basic for MS-DOS and Microsoft Visual Basic for Windows have the same behavior.
REFERENCES
"Visual Basic User's Guide," version 5.0, pages 153-169
For more information about Adding Watch Expressions and using a Debugging Checklist, choose the Search button in Visual Basic Help and type:
debugging
KBCategory: kbusage kbtlc Last reviewed: September 13, 1996 |