Event Procedures
Code in a Visual Basic application is divided into
smaller blocks called procedures. An event procedure
contains code that is executed when an event occurs
(such as when a user clicks a button or types something
in the text box). In chapter 4 (The Classic hello
World Program), you saw what happened when you clicked
the "Show" button. Most events come directly
from the user at the keyboard and mouse running applications
within Windows.
|
When Windows recognizes that a
user triggered an event and the event is not a
system event, it passes that event to the application. |
If you have written an event procedure to respond
to that particular event, your application will respond
to that event. To the contrary, if you haven't written
an event procedure, the event goes unhandled.
An event procedure for a control combines the control's
actual name (specified in the Name property), an underscore
(_), and the event name. For example, if you want
a command button named "Show" to
invoke an event procedure when it is clicked, use
the procedure Show_Click.
Visual Basic supports two kinds of procedures: functions
and subroutines. All event procedures will be subroutines.
A subroutine is indicated by the sub keyword,
and it does not return a value. On the contrary, a
function can return a value to somewhere else in the
program. The keyword Function indicates that
a procedure is a function.
|