The Structure of a VB Program

Broadly speaking, programs can be either procedure driven or event driven . In a procedure-driven program, program flow is predefined. A classic example is a console application: program flow begins at the program entry point (in the case of a .NET console application, it begins with the Main routine) and proceeds along a predictable path until it reaches program termination. In an event-driven program, on the other hand, program flow is not predetermined and is instead controlled by external events (i.e., by the program’s interaction with the user and the system), and possibly by internal events as well.

From the perspective of program structure, the difference between procedure-driven and event-driven programs is less sharp than is usually thought. Both rely on a procedure as an entry point, which in turn can call other functions and subroutines that are visible to it. The major difference is that a procedure-driven program has a single entry point, whereas an event-driven program has multiple entry points. For event-driven programs, these entry points (in addition to the required Main procedure) are event handlers , which are invoked automatically by the .NET Common Language Runtime in response to an event within the code itself or in its environment.

Therefore, regardless of whether an application is procedure driven or event driven, Visual Basic code can be divided into three main categories:

Entry point code

For procedural applications, this ...

Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.