VB6 Tutorial 05: Event Driven Programming

Posted On 2018-03-22 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner,Event,Driven,programming
Tags: VB6 Tutorials Windows
Views: 65

Title Uploaded Size
GotFocus.zip 3/25/2018 8:55:50 AM 1,212
MouseDown_MouseUp.zip 3/25/2018 8:59:31 AM 1,163
MouseMove.zip 3/25/2018 8:59:53 AM 1,129


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

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.

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

VB6Boy has posted a total of 71 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:23.20.165.182

Before you can post, you need to prove you are human. If you log in, this test goes away.




Code Links