Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions Section 4.3. Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create.

Similar presentations


Presentation on theme: "Functions Section 4.3. Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create."— Presentation transcript:

1 Functions Section 4.3

2 Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create modules within our Visual Basic programs.

3 A typical program design - 1

4 Now its time for Functions We have already used Visual Basic built-in functions. Now we talk about writing our own user- defined functions. One key conceptual difference between procedures & functions…..

5 A function always returns exactly value!!!!!!!

6 Function header : Private Function F_name (parameter_list) Result_type Assigning function result: F_name = result Calling a function: We invoke a function by assigning its result to a variable or by using in an output statement. Arguments & parameters must agree, as with procedures. Note!

7 Function arguments & parameters Basically, the same rules apply, whether we’re working with procedures or functions, but... None of a function’s parameters should change value within the function execution –if they do, it’s called a side effect (and it’s not good…)

8 A typical program design - 2 Hierarchy Diagram

9 Program design In this section of our text, most programs are designed to use procedures & functions as follows: –Input procedure –Output procedure that makes a function call Example: p. 135 #138: use two functions: –findletter(alphabet) –findnumber(num)

10 In each of the following examples you should have ONE input procedure, and ONE output procedure. The output procedure will CALL A FUNCTION either in the output line or in an assignment. Page 189 # 14 Page 190 # 17


Download ppt "Functions Section 4.3. Last week, we were introduced to procedures Procedures are used in support of top- down program design. –They are used to create."

Similar presentations


Ads by Google