Datasheet

5. Double-click the button on the form and the IDE will automatically open the code window for
this form. It will then create the necessary code to execute your code when the button is clicked,
like so:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
End Sub
6. In between the Private Sub and End Sub lines, write the code MessageBox.Show(“Hello
World!”)
so that the program appears like this:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(“Hello World!”)
End Sub
7. Now you can run your program. The easiest way is to simply press the F5 button, but if you
find the menus and toolbars easier to use, you’ll find the Start command in the Debug menu.
Either way, when you run your program, you’ll be presented with a simple form with a single
button on it. If you click the button, it will display a message box with the words “Hello World!”
(as shown in Figure 1-6). Congratulationsyou’ve written your first complete Visual Basic
Express program!
Figure 1-6
What you’ve done is create a Windows Application a program designed to run on Windows with a
base form. You then added a button to it and wrote actual code to generate a message dialog box when
the user clicked it.
That Was Too Easy
Yes, I knowthat first program seemed a little too easy, didn’t it? That you needed to write only one
line of code to actually create a program containing a button on a form that produces a message might
seem a little crazy, but that’s what Visual Basic Express is all aboutmaking life as a programmer
incredibly simple.
12
Chapter 1
05_595733 ch01.qxd 12/1/05 1:34 PM Page 12