Академический Документы
Профессиональный Документы
Культура Документы
Modular Design
Function & Procedures
5.4 Modular Design
Top-Down Design
Structured Programming
Advantages of Structured Programming
2
Faculty
Design Terminology
3
Faculty
Top-Down Design
4
Faculty
Top-Down Design Criteria
5
Faculty
Top-Level Design Chart
6
Faculty
Detailed Chart
7
Faculty
Easy to Write
8
Faculty
Easy to Debug
9
Faculty
Easy to Understand
Interconnections of the procedures reveal the modular
design of the program
10
Faculty
Example
Private Sub btnDetermine_Click() Handles btnDetermine.Click
Dim num As Integer
num = 2
MsgBox(Function1(num))
End Sub
Faculty
Devices for Modularity
Sub procedures
Function procedures
12
Faculty
Sub Procedures
Sub ProcedureName()
statements
End Sub
13
Faculty
Calling a Sub Procedure
The statement that invokes a Sub procedure is
also referred to as a Call statement
ProcedureName()
The rules for naming Sub procedures are the same as the rules for
naming variables
14
Faculty
Example
lstBox.Items.Clear()
ExplainPurpose()
lstBox.Items.Add("")
Sub ExplainPurpose()
lstBox.Items.Add("Program displays a sentence")
lstBox.Items.Add("identifying a sum.")
End Sub
15
Faculty
Passing Values
16
Faculty
Arguments and Parameters
Sum(2, 3)
arguments
parameters
displayed
automatically
17
Faculty
Several Calling Statements
ExplainPurpose()
Sum(2, 3)
Sub Sum(ByVal num1 As Double, ByVal num2 As Double)
Sum(4, 6) lstBox.Items.Add("The sum of " & num1 & " and " _
& num2 & " is " & (num1 + num2) & "."
Sum(7, 8) End Sub
Output:
Program displays a sentence identifying a sum.
18
Faculty
Passing Strings and Numbers
Demo("CA", 38)
Note: The variable names in the arguments need not match the
parameter names. For instance, s versus state..
20
Faculty
Calling
21
Faculty
5.3 Function Procedures
22
Faculty
Some Built-In Functions
23
Faculty
Function Procedures
24
Faculty
Example: Form
txtFullName
txtFirstName
25
Faculty
Example: Code
End Sub
txtSideOne
txtSideTwo
txtHyp
27
Faculty
Example: Code
28
Faculty
Function Having No Parameters
29
Faculty
Comparing Function Procedures with Sub
Procedures
Subs are accessed using a Call statement
For example:
result = functionCall
lstBox.Items.Add (functionCall)
30
Faculty
Functions vs. Procedures
31
Faculty