19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

80 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

2. To obtain a list of the general procedures in a program, select (General) from<br />

the Code window's Object box <strong>and</strong> then click on the down-arrow at the right<br />

side of the Procedure box.<br />

3. Sub procedures allow programmers to focus on the main flow of the program<br />

<strong>and</strong> defer the details of implementation. Modern programs use them liberally.<br />

An event procedure acts as a supervisor, delegating tasks to the Sub procedures.<br />

This method of program construction is known as modular or top-down<br />

design.<br />

4. As a rule, a Sub procedure should perform only one task, or several closely<br />

related tasks, <strong>and</strong> should be kept relatively small.<br />

5. After a Sub procedure has been defined, <strong>Visual</strong> <strong>Basic</strong> automatically reminds<br />

you of the Sub procedure’s parameters when you type in Call statements. As<br />

soon as you type in the left parenthesis of a Call statement, a banner appears<br />

giving the names <strong>and</strong> types of the parameters. The help feature is called Parameter<br />

Info. See Figure 3-3.<br />

FIGURE 3-3 The Parameter Info Help Feature<br />

6. In this text, the first line inside a Sub procedure is often a comment statement<br />

describing the task performed by the Sub procedure. If necessary, several comment<br />

statements are devoted to this purpose. Conventional programming practice<br />

also recommends that all variables used by the Sub procedure be listed in<br />

comment statements with their meanings. In this text, we give several examples<br />

of this practice but only adhere to it when the variables are especially numerous<br />

or lack descriptive names.<br />

7. Although both constants <strong>and</strong> expressions can be used as arguments in Call<br />

statements, only variables can be used as parameters in Sub statements.<br />

8. A Sub procedure can call another Sub procedure. If so, after the End Sub of the<br />

called Sub procedure is reached, execution continues with the line in the calling<br />

Sub procedure that follows the Call statement.<br />

9. When you write a Sub procedure without parameters, <strong>Visual</strong> <strong>Basic</strong> automatically<br />

adds a pair of empty parentheses at the end of the Sub procedure name.<br />

However, Call statements should not use the empty parentheses.<br />

10. The first lines of event procedures <strong>and</strong> Sub procedures end with a pair of parentheses.<br />

With the event procedures we have discussed, the parentheses are usually<br />

empty, whereas with Sub procedures, the parentheses often contain<br />

parameters.<br />

3.2 SUB PROCEDURES, PART II<br />

The previous section introduced the concept of a Sub procedure but left some questions unanswered.<br />

Why can’t the value of a variable be passed from an event procedure to a Sub proce-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!