Write Your First Visual Basic Program
The Form has
more events besides the Form_Load event.
How can you find
Click on the Drop-Down List that found in the upper left corner of
the Code Window, where appears right now the text "Form" (Figure 23).
You will see a list of the components that found in your
You have 1 command button with the name "Command1" and 1
Here you select which component's event you want to program.
want to program a form's event, so select "Form" from the list (Figure
Which events the form has?
Click on the Drop-Down List that found
in the upper right corner of
the Code Window, where appears right now the
text "Load" (Figure 24).
You will see
the complete list of the form's events:
Load, LostFocus, MouseDown, MouseMove
Lets program the Form_Unload event.
Select "Unload" from the
form's events list.
The Form_Unload event occurs when the form is being
and this happening when you close the program
(Using the form's X button (Figure 7)).
So the code that you will write in
the Form_Unload event will be launched
when you close the
Insert the following line to the Form_Unload
inserted this line to your Form_Unload event,
Form_Unload event should look like this:
Private Sub Form_Unload(Cancel As
When the form is being loaded at the very start, The
is being executed and a message box with "Hello" text is
When you close the program by clicking the form's X button, the
event is being executed and a message box with "GoodBye"
text is popping.