Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

218 Part II Programming Fundamentals


open up to four Watch windows, numbered Watch 1, Watch 2, Watch 3, and Watch 4.
If you are using Visual Basic 2010 Express, only one Watch window is available. When
you are in debugging mode, you can open these windows by pointing to the Windows
command on the Debug menu, pointing to Watch, and then clicking the window you
want on the Watch submenu. You can also add expressions, such as Age >= 13, to a Watch
window.

Open a Watch window

Tip The Debug Test project is located in the C:\Vb10sbs\Chap08\Debug Test folder.


  1. Click the Start Debugging button on the Standard toolbar to run the Debug Test
    program again.
    I’m assuming that the breakpoint you set on the line Age = TextBox1.Text in the


(^) previous exercise is still present. If that breakpoint isn’t set, stop the program
now, and set the breakpoint by clicking in the Margin Indicator bar next to
the statement, as shown in Step 10 of the previous exercise, and then start the
program again.



  1. Type 20 in the Age text box, and then click Test.


The program stops at the breakpoint and Visual Studio enters debugging mode,
which is where you need to be if you want to add variables, properties, or
expressions to a Watch window. One way to add an item is to select its value in
the Code Editor, right-click the selection, and then click the Add
Watch command.


  1. Select the Age variable, right-click it, and then click the Add Watch command.


Visual Studio opens the Watch 1 window and adds the Age variable to it. The value
for the variable is currently 0, and the Type column in the window identifies the Age
variable as an Integer type.
Another way to add an item is to drag the item from the Code Editor into the Watch
window.


  1. Select the TextBox2.Text property, and then drag it to the empty row in the
    Watch 1 window.
    When you release the mouse button, Visual Studio adds the property and displays its
    value. (Right now, the property is an empty string .)

Free download pdf