Microsoft KB Archive/161736

= XL97: Watch Window Does Not Use Procedure Call Context =

Article ID: 161736

Article Last Modified on 11/7/2000

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q161736





SYMPTOMS
The Watch Window may not display the value of a watch expression in the appropriate context of the selected procedure call.



CAUSE
When you run a procedure in the Immediate Window as part of the debugging process for your macro, it will be added to the list of procedure calls in the Call Stack dialog box. This functionality helps you trace the operation of your code. However, if you select a procedure in the Call Stack dialog box that is listed more than once and click 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 Window multiple times, and you change the value of the variable each time, the Call Stack dialog box cannot be used to trace the different values of the variable. The value of the variable in the Watch Window is the value at the last running of the procedure, regardless of the instance of the procedure call selected in the Call Stack dialog box.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Problem
 Close and save any open workbooks and then open a new workbook. Start the Visual Basic Editor (press ALT+F11). If the Immediate Window is not visible, click Immediate Window on the Insert menu (or press CTRL+G). If the Watch Window is not visible, click Watch Window on the Insert Menu. Click Module on the Insert menu.</li>  In Module1, type the following code: Sub Initial

'Calls the DoubleNum Function, and passes 'the number 2 as the argument. DoubleNum 2

End Sub

Function DoubleNum(Arg1 As Integer)

DoubleNum = Arg1 * 2

'Sets a breakpoint, so we can use the debugging windows. Stop

End Function </li> Click Add Watch on the Debug menu. In the Expression box, type Arg1. Select DoubleNum from the Procedure list, and then click OK.</li> Click Macros on the Tools menu. Click Initial in the Macro Name list, and then click Run.</li></ol>

The Initial procedure will call the DoubleNum function, passing a value of 2 for the Arg1 argument. The Watch Window shows the value of Arg1 equal to 2, and the context is listed as Module1.DoubleNum.

<ol>  Type the following expression in the Immediate Window DoubleNum 5 and press the Enter key.

The value of Arg1 is shown as 5 in the Watch Window. </li> Click Call Stack on the View menu. You will see the item VBAProject.Module1.DoubleNum, listed twice in the Project.Module.Function list. Click the first listing, and then click Show.

The Watch Window still shows the value of Arg1 as 5, even though you selected the first call to the DoubleNum function in the Call Stack dialog box.</li></ol>

<div class="references_section">