
112
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Chapter 8Delegates and Events
8
Delegates and Events
Because Visual Basic is built on the foundation of the .NET Framework, it is
object-oriented. But because it is designed for use in the Microsoft Windows envi-
ronment, it is also event-driven. In standard procedural languages, all statements
encountered in the program are processed from beginning to end. The program
begins at the start of the main routine (or its equivalent) and continues to the end,
sometimes taking detours into other routines, but always as dictated by the orga-
nization of main.
In event-driven programs, a procedure can be called that has no direct or indirect
relation to the main routine. In fact, very little code within a typical event-driven
application is called from main or any of its descendants. Most code is called by
events, user- and system-initiated actions that seek some outlet in your applica-
tion’s code. Events are the natural programming style of any system with multiple
user input possibilities (keyboard, mouse, touch screen, the user pressing the
system’s power button, etc.).
Perhaps you have a program that simulates a cat. Of course you will include a
Meow procedure that emits the language of the cat.
Public Sub Meow( )
Your cat program will need to respond to external stimuli, just like a real ...