Visual Basic tutorial

Learning about Events
Visual Basic is “Event Driven” language.
What does it mean?

Everything that happening, launch an event.
You’ve moved the mouse? The “MouseMove” event has been launched.
You’ve pressed a key? The “KeyPress” event has been launched.

You can program the events.
When the mouse moves, you can change the Form’s color (for example),
and when a key is pressed, You can play a MP3 file.

To start programming the events, double click on the form.
You will see the “Code Window”

The Code Window opened with the Form_Load event.
The Form_Load event occurs when the form is loaded, and this happening
when you start the program.
So the code that you will enter to the Form_Load event will be launched
when the program is being started.

The code that belongs to the Form_Load event should be placed
between Private Sub Form_Load() and End Sub

The Form_Load event should look like this:

Private Sub Form_Load() (The beginning of the Form_Load event)
This is the code that belongs to the Form_Load event
End Sub
(The end of the Form_Load event)

Lets program the Form_Load event.

“MsgBox” is Visual Basic command that launch a message box.
for example, the line:

MsgBox “Hello”
Will launch a message box with the text “Hello”.

Insert the line MsgBox “Hello” to the Form_Load event

Now run your program using the Play button.
When the program is started, a message box with the
text “Hello” is appear

You can leave a response, or trackback from your own site.

Leave a Reply