Partager via


Did you know… You can use the immediate window as a glorified calculator or side-debugger within your debugger - #241

This was tip #20 in my TechEd VS 2008 IDE tips and tricks talk.

When you want to do more than just edit the value of a variable, you can rewrite entire functions or create new ones in the immeidate window.  I found this especially useful when I was doing the math to automate dragging a tool window from a docked location to  a docking target.  I basically had to do the math to calculate a straight line between the two points in order to send the coordinates to the mouse drag functions.  If i did the math wrong, i could pull up the immediate window and play with the calculations over and over again without interfering with the main debugger, meaning that the variables and state of the main debugger would remain the same unless i purposefully modified a value in the immediate window.

A very simple example:  let’s say that you have the basic “hello world” console app, but want to print out the result of some calculation.  Notice how the console app just has “hello world”

Hello World on Output Window

If i put a breakpoint at the very end of this simple console app, i can bring up the immediate window via Debug – Windows – Immediate and do whatever i need.  Let’s say i needed to use the immediate window as a glorified calculator, i can figure out the value of 1+1, as shown below in VB

immediate window calculating 1+1

Since we’re in a console application, you can even have the value of ‘i’ printed to the console window via the immediate window.  This is where you actually want to change the state of your debugger.

Writing 'i' to console window via immediate window

and now the value of 2 appears in the console window.

value of 'i' in console window

Technorati Tags: VS2005Tip,VS2008Tip

Comments

  • Anonymous
    June 19, 2008
    Interesting. I wonder: Can you use this to call a method? or manually fire any event?  Hmmm.....

  • Anonymous
    June 19, 2008
    There's a simpler way, you don't need the "i = ..." In the immediate windows you can simply write "?1+3" naturally you can also do more complex math... :-) "?(1+3)*125 + Math.Sqrt(124.5d)"

  • Anonymous
    June 19, 2008
    The comment has been removed

  • Anonymous
    July 10, 2008
    The comment has been removed

  • Anonymous
    November 17, 2008
    Сара Форд (Sara Ford) в своем блоге дает массу интересных советов по использованию Visual Studio . Текущий

  • Anonymous
    January 09, 2009
    本篇包括tip241-tip250 http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-25.html #241...

  • Anonymous
    March 12, 2009
    When my jQuery code doesn’t work, it usually means I’ve done something terribly wrong with my selectors.