XL97: Watch Window Does Not Use Procedure Call Context

ID: Q161736

The information in this article applies to:

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 this to be a problem in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Problem

 1. Close and save any open workbooks and then open a new workbook.

 2. Start the Visual Basic Editor (press ALT+F11).

 3. If the Immediate Window is not visible, click Immediate Window on
    the Insert menu (or press CTRL+G).

 4. If the Watch Window is not visible, click Watch Window on the Insert
    Menu.

 5. Click Module on the Insert menu.

 6. 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

 7. Click Add Watch on the Debug menu. In the Expression box, type
    "Arg1" (without the quotation marks). Select DoubleNum from the
    Procedure list, and then click OK.

 8. Click Macros on the Tools menu. Click Initial in the Macro Name
    list, and then click Run.

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.

 9. 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.

10. 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.

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q106498
   TITLE     : XL: Watch Pane Does Not Use Procedure Call Context

REFERENCES

For more information about the Watch window, click the Office Assistant, type "watch", click Search, and then click to view "Watch Window".

For more information about the Immediate window, click the Office Assistant, type "immediate", click Search, and then click to view "Immediate Window".

For more information about the Call Stack Window, click the Office Assistant, type "calls", click Search, and then click to view "Call Stack Command (View Menu)".

Additional query words: XL97

Keywords          : kbprg kbtool kbdta KbVBA 
Version           : WINDOWS:97
Platform          : WINDOWS
Issue type        : kbprb

Last Reviewed: December 8, 1998