Datasheet

The Command and Immediate Windows
The Command and Immediate windows enable you to execute commands while the program is stopped
in the debugger. One of the more useful commands in each of these windows is the
Debug.Print state-
ment. For example, the command
Debug.Print x displays the value of the variable x.
You can use a question mark as an abbreviation for
Debug.Print. The following text shows how the
command might appear in the Command window. Here the
> symbol is the command prompt provided
by the window and
123 is the result: the value of variable x. In the Immediate window, the statement
would not include the > character.
>? x
123
The command >immed tells the Command window to open the Immediate window. Conversely, the
command
>cmd tells the Immediate window to open the Command window.
Although there is some overlap between these two windows, they serve two mostly different purposes.
The Command window can issue commands to the Visual Studio IDE. Typically, these are commands
that appear in menus or toolbars, or that could appear in menus and toolbars. For example, the follow-
ing command uses the Debug menu’s QuickWatch command to open a QuickWatch window for the
variable
first_name.
>Debug.QuickWatch first_name
One particularly useful command is Tools.Alias. This command lists command aliases defined
by the IDE. For example, it indicates that
? is the alias for Debug.Print and that ?? is the alias for
Debug.QuickWatch.
The Command window includes some IntelliSense support. If you type the name of a menu, for example
Debug or Tools, IntelliSense will display the commands available within that menu.
While the Command window issues commands to the IDE, the Immediate window executes Visual Basic
statements. For example, suppose that you have written a subroutine named
CheckPrinter. Then the
following statement in the Immediate window executes that subroutine.
CheckPrinter
Executing subroutines in the Immediate window lets you quickly and easily test routines without writ-
ing user interface code to handle all possible situations. You can call a subroutine or function, passing it
different parameters to see what happens. If you set breakpoints within the routine, the debugger will
pause there.
Similarly, you can also set the values of global variables and then call routines that use them. The
following Immediate window commands set the value of the
m_PrinterName variable and then
call the
CheckPrinter subroutine.
m_PrinterName = “LP_REMOTE”
CheckPrinter
33
Chapter 1: IDE
37055c016.qxd 4/8/07 12:46 PM Page 33