Datasheet

P1: GIG
WY006-01 WY006-Sample WY006-Sample-v3.cls January 29, 2004 17:49
Welcome to Visual Basic .NET
7. A window known as a message box appears, welcoming the person whose name was entered in
the textbox on the formin this case Thomas (see Figure 1-21).
Figure 1-21
8. After you close the message box by clicking the OK button, click on the Exit button on your form.
The application will close and you will be brought back to the Visual Basic .NET IDE.
How It Works
The code that you added to the click event for the OK button will take the name that was entered in the
text box and use it as part of the message that was displayed in Figure 1-21.
The rst line of text entered in this procedure is actually a comment. Comments in Visual Basic .Net begin
with a single quote () and everything following is considered a comment.
The MessageBox.Show method displays a message box that accepts various parameters. As used in
your code, you have passed the string text to be displayed in the message box. This is accomplished
through the concatenation of string constants dened by text enclosed in quotes. Concatenation of strings
is performed through the use of the ampersand (&) character.
In the code that follows, you have concatenated a string constant of Hello,followed by the
value contained in the Text property of the txtName text box control followed by a string constant
of "! Welcome to Visual Basic .NET.". The second parameter being passed to the
MessageBox.Show method is the caption to be used in the title bar of the Message Box dialog box.
Finally, the underscore (
) character used at the end of the lines in your code below enables you to split
your code onto separate lines. This tells the compiler that the rest of the code for the parameter is
continued on the next line. This is really useful when building long strings as it allows you to view the
entire code fragment in the code editor without having to scroll the code editor window to the right to
view the entire line of code.
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
'Display a message box greeting the user
MessageBox.Show("Hello, " & txtName.Text & _
"! Welcome to Visual Basic .NET", _
"HelloUser Message")
End Sub
The next procedure that you added code for was the Click event of the Exit button. Here you simply enter
the code: Me.Close(). As explained earlier, the Me keyword refers to the form itself. The Close method
of the form closes the form and releases all resources associated with it thus ending the program.
31