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 statement. For example, in the Command window, the command Debug.Print x displays the value of the variable x. In the Immediate window, the statement must follow normal Visual Basic syntax so the command is Debug.Print(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 (you need to type the > in the Immediate window) 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 do or could appear in menus and toolbars. For example, the following 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, >Tools.Alias ? indicates that ? is the alias for Debug.Print and >Tools.Alias ?? indicates 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.

The Command window issues commands to the IDE. In contrast, 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

You can execute subroutines in the Immediate window to quickly and easily test routines without writing 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.

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 PrinterName variable and then call the CheckPrinter subroutine:

PrinterName = "LP_REMOTE"
CheckPrinter

You can execute much more complex statements in the Command and Immediate windows. For example, suppose that your program uses the following statement to open a file for reading:

Dim fs As FileStream = File.OpenRead(
 "C:Program FilesCustomer OrdersSummary" &
 DateTime.Now().ToString("yymmdd") & ".dat")

Suppose that the program is failing because some other part of the program is deleting the file. You can type the following code (all on one line) into the Immediate window to see if the file exists. As you step through different pieces of the code, you can use this statement repeatedly to learn when the file is deleted.

?System.IO.File.Exists("C:Program FilesCustomer OrdersSummary" &
  DateTime.Now().ToString("yymmdd") & ".dat")

The Immediate window evaluates the complicated string expression to produce a filename. It then uses the System.IO.File.Exists command to determine whether the file exists and displays True or False accordingly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.150.2