Parts of a Program

A program is made up of the basic parts shown in Figure 2-1.

Project

Is the workbook where the program is stored. Each workbook has one Visual Basic project.

Classes and modules

Store the code associated with the workbook and the sheets the workbook contains. Classes and modules help organize the procedures in your program.

Procedures

Perform the program’s work. You can’t do anything in Visual Basic without creating at least one procedure.

The main parts of a program

Figure 2-1. The main parts of a program

Variables

Store values used by your program.

Conditional statements

Make decisions within procedures.

Loops

Repeat actions. Together, conditional statements and loops form the logic that your procedure uses to accomplish its task.

Expressions

Evaluate a combination of items to return a single result. Expressions are the smallest unit of work in a program and they usually involve operators such as +, -, *, or & (combine strings).

The following sections describe these parts in detail. If you are new to programming, I recommend that you follow along with the samples carefully. I take a top-down approach and I’ve tried to be clear about how, when, and why you use each part.

If you’re an experienced programmer, the top-down organization of this chapter should work well for you as a reference. If you think you know this already, I recommend that you read the sections "Classes and Modules,” ...

Get Programming Excel with VBA and .NET 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.