Search Tools Links Login

VB6 Tutorial 05: Event Driven Programming


Visual Basic is an event driven programming language. Before proceeding to the next chapter, it is very important to have a good concept of event driven programming.

The common events are Click, DblClick, Load, MouseMove, MouseDown, MouseUp, KeyPress, KeyUp, KeyDown, GotFocus, LostFocus etc.

When the user clicks , presses key or moves the mouse, the particular block of code of the corresponding event procedure is executed. Then the program behaves in a certain way. This is event driven programming. When you fire an event, the code in the event procedure is executed, and then visual basic does what the code in the event procedure instructs to do. For example, in the first sample program, when you click the Print button, click event is fired. Then the code in the click event procedure gets executed. The code instructs to print a text on the form. After that you see a text printed on the form. This is the concept of event driven programming. That means , the code is not executed from top to bottom but it works when the corresponding event procedure is invoked.

Example

Write the following code in the DblClick event procedure of the form.

Private Sub Form_DblClick()
    Print "You have double clicked" 
End Sub

When you double-click on the form, the DblClick event procedure of the Form object is invoked and the code in the DblClick event procedure is executed. As a result, the code instructs to print a text on the form.

event execution

There are three sample projects attached to this post, up in the top section. Give them a try, and experiment with them a bit.

QuickHint:

Sample programs and a detailed explanation of other events are given in the appropriate lessons.

Later in this series, there will be a lesson about to how to name a control, a very important programming guide for use with any computer language.

About this post

Posted: 2018-03-22
By: vb6boy
Viewed: 1,937 times

Categories

Visual Basic 6

VB6 Tutorial

Attachments

MouseMove.zip
Posted: 3/25/2018 8:59:53 AM
Size: 1,129 bytes

MouseDown_MouseUp.zip
Posted: 3/25/2018 8:59:31 AM
Size: 1,163 bytes

GotFocus.zip
Posted: 3/25/2018 8:55:50 AM
Size: 1,212 bytes


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.