Using Master Procedures and Subprocedures

When your VBA procedure gets larger, it may be difficult to maintain its many lines of code. To make your program easier to write, understand, and change, you should use a structured approach. When you create a structured program, you break a large problem into small problems that can be solved one at a time. In VBA, you do this by creating a master procedure and one or more subordinate procedures. Because both master procedures and subordinate procedures are subroutines, you declare them with the Sub keyword. The master procedure can call the required subroutines and pass arguments to them. It may also call functions.

The following hands-on exercise demonstrates the AboutUser procedure. The procedure requests the user's full name, then extracts the first and last name from the fullName string. The last statement displays the user's last name followed by a comma and the first name. As you read further, this procedure will be broken down into several tasks to demonstrate the concept of using master procedures, subprocedures, and functions.

0 0

Post a comment