Skip to content

Commit 8531d57

Browse files
committed
sync
1 parent 19805e7 commit 8531d57

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: Use the Immediate Window
3+
description: Learn how to use the Immediate window to debug and evaluate expressions, execute statements, and print variable values.
4+
ms.date: 08/05/2025
5+
ms.topic: how-to
6+
dev_langs:
7+
- VB
8+
f1_keywords:
9+
- VS.ImmediateWindow
10+
helpviewer_keywords:
11+
- design-time expression evaluation
12+
- Immediate window
13+
- first-chance exception notifications
14+
author: Mikejo5000
15+
ms.author: mikejo
16+
manager: mijacobs
17+
ms.subservice: general-ide
18+
---
19+
# Use the Immediate window
20+
21+
This article explains how to use the **Immediate** window to debug and evaluate expressions, execute statements, and print variable values. The **Immediate** window evaluates expressions by building and using the currently selected project.
22+
23+
To display the **Immediate** window, first open a project to edit, and then choose **Debug** > **Windows** > **Immediate** or press **Ctrl**+**Alt**+**I**. You can also enter *Debug.Immediate* in the **Command** window.
24+
25+
The **Immediate** window supports IntelliSense.
26+
27+
## Display the values of variables
28+
29+
The **Immediate** window is useful when you debug an app. For example, to check the value of a variable `varA`, you can use the [Print command](../../ide/reference/print-command.md):
30+
31+
```cmd
32+
>Debug.Print varA
33+
```
34+
35+
The question mark (`?`) is an alias for `Debug.Print`, so this command can also be written:
36+
37+
```cmd
38+
? varA
39+
```
40+
41+
Both versions of this command return the value of the variable `varA`.
42+
43+
> [!TIP]
44+
> 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](command-window.md).
45+
46+
## Design-time expression evaluation
47+
48+
You can use the **Immediate** window to execute a function or subroutine at design time.
49+
50+
### Execute a function at design time
51+
52+
1. Copy the following code into a Visual Basic console app:
53+
54+
```vb
55+
Module Module1
56+
57+
Sub Main()
58+
MyFunction(5)
59+
End Sub
60+
61+
Function MyFunction(ByVal input as Integer) As Integer
62+
Return input * 2
63+
End Function
64+
65+
End Module
66+
```
67+
68+
1. On the **Debug** menu, choose **Windows** > **Immediate**.
69+
70+
1. Type `?MyFunction(2)` in the **Immediate** window and press **Enter**.
71+
72+
The **Immediate** window runs `MyFunction` and displays `4`.
73+
74+
If the function or subroutine contains a breakpoint, Visual Studio breaks execution at the appropriate point. You can then use the debugger windows to examine your program state. For more information, see [Walkthrough: Debug at design time](../../debugger/walkthrough-debugging-at-design-time.md).
75+
76+
You can't 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.
77+
78+
### Design-time expression evaluation in multi-project solutions
79+
80+
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 can't be evaluated in the current context, you receive an error message. If you're attempting to evaluate a function in a project that's not the startup project for the solution and you receive an error, try selecting the project in Solution Explorer and attempt the evaluation again.
81+
82+
## Enter commands
83+
84+
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 your previously used commands.
85+
86+
|Task|Solution|Example|
87+
|----------|--------------|-------------|
88+
|Evaluate an expression.|Preface the expression with a question mark (?).|`? a+b`|
89+
|Temporarily enter Command mode while in Immediate mode (to execute a single command).|Enter the command, prefacing it with a greater than sign (>).|`>alias`|
90+
|Switch to the Command window.|Enter `cmd` into the window, prefacing it with a greater than sign (>).|`>cmd`|
91+
|Switch back to the Immediate window.|Enter `immed` into the window without the greater than sign (>).|`immed`|
92+
93+
## Mark mode
94+
95+
When you select 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.
96+
97+
## Examples
98+
99+
The following example shows four expressions and their result in the **Immediate** window for a Visual Basic project.
100+
101+
```cmd
102+
j = 2
103+
Expression has been evaluated and has no value
104+
105+
? j
106+
2
107+
108+
j = DateTime.Now.Day
109+
Expression has been evaluated and has no value
110+
111+
? j
112+
26
113+
```
114+
115+
## First-chance exception notifications
116+
117+
In some settings configurations, first-chance exception notifications are displayed in the **Immediate** window.
118+
119+
### Toggle first-chance exception notifications in the Immediate window
120+
121+
1. On the **View** menu, select **Output**.
122+
123+
2. Right-click on the text area of the **Output** window, and then select or deselect **Exception Messages**.
124+
125+
## Related content
126+
127+
- [Navigating through code by using the debugger](../../debugger/navigating-through-code-with-the-debugger.md)
128+
- [Command Window](../../ide/reference/command-window.md)
129+
- [Overview of the debugger](../../debugger/debugger-feature-tour.md)
130+
- [Debug at design time](../../debugger/walkthrough-debugging-at-design-time.md)
131+
- [Visual Studio Command Aliases](../../ide/reference/visual-studio-command-aliases.md)
132+
- [Use regular expressions in Visual Studio](../../ide/using-regular-expressions-in-visual-studio.md)
123 KB
Loading
26.8 KB
Loading
82.1 KB
Loading

0 commit comments

Comments
 (0)