Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

134 Part II Programming Fundamentals


Note Visual Studio provides both the MsgBox function and the MessageBox class for displaying
text in a message box. The MessageBox class is part of the System.Windows.Forms namespace; it
takes arguments much like MsgBox, and it is displayed by using the Show method. I’ll use both
MsgBox and MessageBox in this book.

Now you’ll add a MsgBox function to the Input Box program to display the name that the
user enters in the Input Box dialog box.

Display a message by using the MsgBox function


  1. If the Code Editor isn’t visible, double-click the Input Box button on the Input Box form.


The Button1_Click event procedure appears in the Code Editor. (This is the code you
entered in the last exercise .)


  1. Select the following statement in the event procedure (the last line):


Label1.Text = FullName
This is the statement that displays the contents of the FullName variable in the label.


  1. Press the DELETE key to delete the line.


The statement is removed from the Code Editor.


  1. Type the following line into the event procedure as a replacement:


MsgBox(FullName, , "Input Results")
This new statement will call the MsgBox function, display the contents of the FullName
variable in the dialog box, and place the words Input Results in the title bar. (The
optional Buttons argument and the ButtonClicked variable are irrelevant here and have
been omitted .) Your event procedure looks like this in the Code Editor:
Free download pdf