Procedures

Procedures are named blocks of code that perform a task. I’ve shown a lot of procedures already and I feel a little bad about waiting this long to define that term. Procedures can have arguments , which let you pass values in to the procedure from somewhere, and they may return values through their name. Figure 2-5 illustrates these parts using the CubeRoot example from Chapter 1.

Visual Basic has four kinds of procedures:

Sub procedures

Perform a task but don’t have return values.

Function procedures

Perform a task and return a value as their result.

Parts of a procedure

Figure 2-5. Parts of a procedure

Property procedures

Get or set a value in an object or module.

Event procedures

A special kind of Sub procedure that respond to events that occur in Excel. Only classes can contain event procedures.

The following sections explain these different types of procedures and how you use them.

Get Programming Excel with VBA and .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.