VB6 Tutorial 05: Event Driven Programming
|MouseMove.zip||3/25/2018 8:59:53 AM||1,129|
|MouseDown_MouseUp.zip||3/25/2018 8:59:31 AM||1,163|
|GotFocus.zip||3/25/2018 8:55:50 AM||1,212|
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.
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.
There are three sample projects attached to this post, up in the top section. Give them a try, and experiment with them a bit.
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.
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.