The following walkthrough demonstrates use of the Watch window to monitor the value of a condition in a Do loop that searches for a name:
1.
Create a form with a button (btnPush) and a text box (txtBox). Then double-click on the button, and enter the following event procedure:
Private Sub btnPush_Click(...) Handles btnPush.Click'Look for a specific name.Dim searchName As String, name As String = ""Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")searchName = InputBox("Name:") 'Name to search for in listDo While (name <> searchName) And (sr.Peek <> 1)name = sr.ReadLineLoopsr.Close()If name = searchName ThentxtBox.Text = nameElsetxtBox.Text = "Name not found"End IfEnd Sub
2.
Access Windows Notepad, enter the following lines of data, and save the file in the program's Debug subfolder inside the bin folder with the name DATA.TXT:
Bert Ernie Grover Oscar
[Page 636]
3.
Place the cursor on the line beginning "Private Sub," press the right mouse button, and click on "Run to Cursor." The program will execute, and the form will appear.
4.
Click on the button. The yellow arrow points to the header of the event procedure.
5.
Click on the variable searchName, click the right mouse button, and click on "Add Watch." The variable searchName has been added to a window titled Watch.
6.
Repeat Step 5 for the variable name.
7.
Press F8 four times to execute the File.OpenText statement and the statement containing InputBox. Enter the name "Ernie" in the input dialog box, and then click OK.
8.
Press F8 repeatedly until the entire event procedure has been executed. Pause after each keypress, and notice how the values of the expressions in the Watch window change.