ObjectSharp Blogs

You are currently viewing

Dave Lloyd's 2 Cents

A .NET Developer's Perspective


The Immediate Window

I notice a lot of developers do not use the Immediate window. If you are one of those users,  do yourself a favour and check it out. It's terribly useful. For those of you who are not familiar with it here are some highlights to get you started.

The window I'm talking about in VS 2003 is the Command Window. This window can be used to either issue commands or to debug and evaluate expressions in Visual Studio .net. To open this window, press CTRL+ALT+A, or click on the menu View->OtherWindows->Command Window

For the record I believe I heard these two windows will be seperated in Whidbey.

Below is a quick description of the two modes.

Mode

Title Bar Displays Description
Command Mode Command Window Allows the developer to perform any command available in Visual Studio via a command line interface.
Immediate Mode Command Window - Immediate Used when debugging an application for evaluating expressions, print variable values, or execute statements. It can also be used to change the value of a variable during debug or even to execute a function or statement.

How to switch between the two modes?

  • When you are in command mode you can enter the command >immed to switch to immediate mode.
  • When you are in Immediate mode you can switch to command mode by typing >cmd
  • If you wanted to execute one command in immediate mode prefix it with a > ie: >alias

Immediate Window:

This is the mode I use most. It's like a command line quickwatch, but it has intellisense. To evaluate an expression you must prefix it with a ?

  • ?this.Order.OrderTable(0).itemarray
  • ?this.Order.OrderTable(0).CustomerId
  • ?this.Order.OrderTable.count

In previous versions of the Immediate window the UP and DOWN ARROW keys move the cursor to previous commands. In VS .Net they allow you to scroll through previously issued commands. If you scroll to a command highlight it and hit enter it will be copied as the next command to be executed.
Once in a project, the Command window can be opened in Immediate mode by pressing CTRL+ALT+I, or click on the menu Debug->Windows->Immediate.

One more quick tip. You can copy your command from the immediate window into the watch window. So in other words get it right with the help of intellisence then paste it into the watch window so you can see it permanently.

The Command Window:

Just to give fair time to both modes. The Command Window makes full use of intellisense to help you find and execute a command within VS.

You can also create your own alias for any command for example: You can type the following to save all the files in your solution.

 

However, if you used this command a lot you could create a shorter alias of this command like fs.
To create an alias enter the following into the command window.

>

From now on you can just type fs to perform a file.Saveall

To see a complete list of aliased commands just type alias in the Command Window and it will list all the aliased commands.

 

Comments

  • TrackBack July 13, 2004 10:07 AM

  • dave August 5, 2004 11:31 PM

    Thank you very very much. u are a savior. it's sure worth more than 2 cents.

  • dave August 5, 2004 11:36 PM

    Thanks John. When someone finds a an entry useful it makes it all worth while. :)

  • dave September 7, 2004 7:12 PM

    I will be making more use of this feature
    Thanks

  • dave December 21, 2004 7:27 AM

    having dificulty with the immedite window. All I get is the response.
    "The expression cannot be evaluated while in design mode."

    Can you help?

  • dave December 21, 2004 9:01 AM

    The immediate window can only be used when running/debugging the application.

  • dave January 5, 2005 5:10 PM

    I called a member function in the immediate window that outputs messages. However, the call in the immdiate window only prints out the first section of the messages followed by
    < More... (The first 0 of 4 items were displayed.) >
    Does anyone know how to display the entire output? I tried Space, Tab, ..... None of these
    keys works. Thanks.

  • dave January 8, 2005 1:25 PM

    Richard...
    It looks like you are not returning a string but rather a character array. If you define your return type as a string you would see the whole thing in the immediate window.

    If you want to see parts of the array you could include the index of the item you wanted to see.

    For example: if your method signature is

    char[] ReturnString()

    You could put this into the immediate window to see the 42nd entry

    ?ReturnString()[42]

  • dave January 30, 2005 3:10 AM

    John,

    On that last question, how do you get the immediate window to display the contents of a large object. Say you type

    ?MyArray

    where the array has 1120 elements.

    What you get is the first 100 items and then the message

    < More... (The first 100 of 1120 items were displayed.) >

    Is there a way of simply prompting the output of the next 100 items and so on ?

    Thanks

  • dave February 10, 2005 7:26 AM

    I always used to use the Immediate window in VS6 to quickly check I had certain functions/calculations correct. I could just enter ?2+2 and it would happily return the answer 4. Is there no way of doing this in VS7 without entering the debug mode? If I try it, I keep getting "The expression cannot be evaluated while in design mode.".

  • dave February 10, 2005 8:36 AM

    I don't think so. I have tried but it only seems to work when you are degugging.

  • dave February 15, 2005 1:24 PM

    So HOW do you display the REST OF THE RETURNED RESULTS? I want to view the Rest of the 1120 Items and dont want to keep guessing.....

  • dave February 21, 2005 8:18 AM

    HOW do you display the REST OF THE RETURNED RESULTS? I want to view the Rest of the 1120 Items... anyone??

  • TrackBack March 13, 2005 11:47 PM

  • TrackBack May 11, 2005 9:50 PM

  • dave November 10, 2005 7:28 AM

    How do you display all of the results in the Immediate window? When degging, I often type ?object where object is some object so I can see all the methods/properties but the window often does not show all. I get a message similar to '< More... (The first 100 of 1120 items were displayed.) >'. How can I see the rest of the object members?

  • dave May 14, 2006 10:27 PM

    Thanks.

    I found the immediate window really useful but when I opened the command window again I couldn't for the life of me figure how to get it to immediate mode.

  • dave May 15, 2006 7:30 AM

    Have someone faced this problem?
    Suddenly I couldn't find The Immediate Window,
    in runtime mode in Visual Studio 2003. It worked before.
    It also works, I can see the window in design mode but that is not so usefull.
    When I press CTRL+ALT+A in runtime mode I can see that The Immediate Window is getting focus because the window I was in when I pressed CTRL+ALT+A is losing focus. But I can't see the window.
    Thanks for helping.

  • tramadol hcl March 19, 2007 10:54 PM

    news

  • cheapest cialis March 19, 2007 10:54 PM

    news

Leave a Comment

(required) 
(optional)
(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS