In subsequent notes we will how to break this sequential flow of control using conditional statements, looping and recursion).
Consider this program that displays several lines. When you run it, you see that it displays five lines in the TextBox, not just one as in our earlier example. The event handler that executes when the user clicks the "Display the greeting" button has six statements, one to clear the TextBox and five to display the greeting lines:
When the program executes, the message seems to appear all at once, but the speed of the computer has deceived you. In fact, the instructions execute in sequence, one at a time. The computer does not go on to the next instruction until the one it is working on is complete. You can see this if you run the message display program with a delay.
When your programs do not do what you wish them to, you will often be able to discover the bug by pretending to be the computer and slowly stepping through the instruction in order in your mind.
Finally, note that both the event handler listed above and the Clear the Screen event handler:
use the Clear method of the TextBox.
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
txtGreet.Clear()
txtGreet.AppendText("Hello my friend!" & vbCrLf)
txtGreet.AppendText("You are looking good." & vbCrLf)
txtGreet.AppendText("Are you married?" & vbCrLf)
txtGreet.AppendText("What is your phone number?" & vbCrLf)
txtGreet.AppendText("Goodbye my friend!")
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtGreet.Clear()
End Sub