Bohn
Bohn

Reputation: 26919

How can I add variables to the Watch window

Visual Studio 2008 Pro: Ok! from the Customize section I added the toolbar commands for Watch,QuickWatch,...to the Debug menu but I want to carefully watch one variable. How do we add it to the Watch? I highlight it and try to add it but it is disabled. I want to be able to first adding some variables of interest to the watch and then start debugging the program.

Upvotes: 3

Views: 24127

Answers (2)

Scott Wegner
Scott Wegner

Reputation: 7483

You will be able to add, view and remove variables from the Watch Mode when you are running under the debugger and execution is paused. The easiest way to get into such a state:

  1. Open your project in Visual Studio
  2. Set a breakpoint in the code within the scope of a variable you'd like to watch. Make sure that the code branch you're breaking on will be executed.
  3. Hit F5 or go to Debug > Start Debugging
  4. When the breakpoint is hit, add your variable to the watch window in any of the following ways:
    • Right click on the variable in code, and select "Add Watch"
    • Right click on the variable in the "Locals" windows, and select "Add Watch"
    • Type the variable name into a new row in the Watch pane itself.

Afterwards, you should see the variable name and value in the watch pane. The value will be updated as you step through the code and any time you pause execution or hit a breakpoint.

Upvotes: 2

Mikael Östberg
Mikael Östberg

Reputation: 17146

You need to be in debugging in order to add variables to the Watch Window.

When debugging, you can just right click a variable and choose to add it to the watch.

Upvotes: 3

Related Questions