This article applies to Visual Studio 2015. If you're looking for Visual Studio 2017 documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2017. Download it here.
The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate, or press CTRL+ALT+I.
You can use this window to issue individual Visual Studio commands. The available commands include
EvaluateStatement, which can be used to assign values to variables. The Immediate window also supports IntelliSense.
Displaying the Values of Variables
This window can be particularly useful while debugging an application. For example, to check the value of a variable
varA, you can use the Print Command:
The question mark (?) is an alias for
Debug.Print, so this command can also be written:
Both versions of this command will return the value of the variable
To issue a Visual Studio command in the Immediate window, you must preface the command with a greater than sign (>). To enter multiple commands, switch to the Command window.
Design Time Expression Evaluation
You can use the Immediate window to execute a function or subroutine at design time.
To execute a function at design time
Copy the following code into a Visual Basic console application:
Module Module1 Sub Main() MyFunction(5) End Sub Function MyFunction(ByVal input as Integer) As Integer Return input * 2 End Function End Module
On the Debug menu, click Windows, and then click Immediate.
?MyFunction(2)in the Immediate window and press Enter.
The Immediate window will run
If the function or subroutine contains a breakpoint, Visual Studio will break execution at the appropriate point. You can then use the debugger windows to examine your program state. For more information see Walkthrough: Debugging at Design Time.
You cannot use design time expression evaluation in project types that require starting up an execution environment, including Visual Studio Tools for Office projects, Web projects, Smart Device projects, and SQL projects.
Design Time Expression Evaluation in Multi-Project Solutions
When establishing the context for design time expression evaluation, Visual Studio references the currently selected project in Solution Explorer. If no project is selected in Solution Explorer, Visual Studio attempts to evaluate the function against the startup project. If the function cannot be evaluated in the current context, you will receive an error message. If you are attempting to evaluate a function in a project that is not the startup project for the solution and you receive an error, try selecting the project in Solution Explorer and attempt the evaluation again.
You must enter the greater than sign (>) when issuing Visual Studio commands in the Immediate window. Use the UP ARROW and DOWN ARROW keys to scroll through previously issued commands.
|Evaluate an expression.||Preface the expression with a question mark (?).||
|Temporarily enter Command mode while in Immediate mode (to execute a single command).||Enter the command, prefacing it with a greater than sign (>).||
|Switch to the Command window.||Enter
|Switch back to the Immediate window.||Enter
When you click on any previous line in the Immediate window, you shift automatically into Mark mode. This allows you to select, edit, and copy the text of previous commands as you would in any text editor, and paste them into the current line.
The Equals (=) Sign
The window used to enter the
EvaluateStatement command determines whether an equals sign (=) is interpreted as a comparison operator or as an assignment operator.
In the Immediate window, an equals sign (=) is interpreted as an assignment operator. So, for example, the command
will assign to variable
varA the value of variable
In the Command window, by contrast, an equals sign (=) is interpreted as a comparison operator. You cannot use assignment operations in the Command window. So, for example, if the values of variables
varB are different, then the command
will return a value of
First-Chance Exception Notifications
In some settings configurations, first-chance exception notifications are displayed in the Immediate window.
To toggle first-chance exception notifications in the Immediate window
On the View menu, click Other Windows, and click Output.
Right-click on the text area of the Output window, and select or deselect Exception Messages.
Navigating through Code with the Debugger
Debugging in Visual Studio
Walkthrough: Debugging at Design Time
Visual Studio Command Aliases
Using Regular Expressions in Visual Studio