222 Part II Programming Fundamentals
The following exercises demonstrate how the Immediate and Command windows work.
I discuss these windows together because, with the following special commands, you can
switch between them:
n In the Immediate window, the >cmd command switches to the Command window.
n In the Command window, the immed command switches to the Immediate window.
The exercises assume that you’re debugging the Debug Test program in debugging mode.
Use the Immediate window to modify a variable
- Click the Immediate button on the Standard or Debug toolbar. (Alternatively, you can
click the Debug menu, point to Windows, and then click Immediate .)
When you select the command, Visual Studio opens the Immediate window and prepares
the compiler to receive commands from you while the Debug Test program is running.
This is a very handy feature because you can test program conditions on the fly, without
stopping the program and inserting program statements in the Code Editor. - In the Immediate window, type Age = 17, and then press ENTER.
You’ve just used the Immediate window to change the value of a variable. The value of
the Age variable in the Watch window immediately changes to 17, and the next time
the If statement is executed, the value in the TextBox2.Text property will change to
“You’re a teenager .” Your Immediate window looks like this:
- Type the following statement in the Immediate window, and then press ENTER:
TextBox2.Text = "You're a great age!"
The Text property of the TextBox2 object is immediately changed to “You’re a great
age!” In the Immediate window, you can change the value of properties, as well as
variables.
- Display the Watch 1 window if it is not currently visible. (Click the Watch 1 tab in the
Visual Studio IDE to do this .)