
The Structure of a Visual Basic Program | 97
Program
Structure
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Calling Routines from Event Handlers
Once processing has been directed to one of your event handlers, it’s time to do
some work. Of course, you can write every bit of processing code right there in
the event-handling routine, but for readability, a divide-and-conquer approach
often works better. An event handler can call methods, functions, and proce-
dures, and can set and retrieve property values, all from classes in your own
application or from the .NET Framework Class Library. In Example 6-3, the
SaveAllData command button’s Click event demonstrates this approach to event
handling by calling
SaveDetails, a method in some other part of the code, to do
most of the work.
The
SaveDetails method contains all the code to actually save the details, and it
can be called from anywhere in the class (or from other classes, if it is public).
Placing code in custom procedures not only improves readability of the code, it
centralizes the work, making it possible to use the same collection of source code
statements from multiple places in your application.
Writing Custom Procedures
Custom procedures can be added to any class, structure, or module in your appli-
cation. Visual Basic includes three main types of custom procedures or routines: ...