4.2. Immediate Window

Quite often when you are writing code or debugging your application, you will want to evaluate a simple expression either to test a bit of functionality or to remind yourself of how something works. This is where the Immediate window comes in handy. This window enables you to run expressions as you type them. Figure 4-2 shows a number of statements — from basic assignment and print operations to more advanced object creation and manipulation.

Figure 4.2. Figure 4-2

Although you can't do explicit variable declaration (for example, Dim x as Integer), it is done implicitly via the assignment operator. The example shown in Figure 4-2 shows a new customer being created, assigned to a variable c, and then used in a series of operations.

The Immediate window supports a limited form of IntelliSense, and you can use the arrow keys to track back through the history of previous commands executed. Variable values can be displayed by means of the Debug.Print statement. Alternatively, you can use the ? alias.

In earlier versions of Visual Studio, your application had to be in Break mode (i.e., at a breakpoint or pausing execution) for the expressions to be evaluated. Although this is no longer a requirement, your solution cannot have any compile errors. When you execute a command in the Immediate window without being in Break mode, Visual Studio will build the solution and then execute the command. If the command execute code has an active breakpoint, the command will break there. This can be useful if you are working on a particular method that you want to test without running the entire application.

You can access the Immediate window via the keyboard chord Ctrl+Alt+I, but if you are working between the Command and Immediate windows you may want to use the predefined aliases cmd and immed, respectively.

Note that in order to execute commands in the Immediate window you need to add > as a prefix (e.g., >cmd to go to the Command window); otherwise Visual Studio tries to evaluate the command.

Also, you should be aware that the language used in the Immediate window is that of the active project. The examples shown in Figure 4-2 will work only if a Visual Basic project is currently active.

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

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