Ch05
Ch05
Procedures
5.1 Function Procedures
5.2 Sub Procedures, Part I
5.3 Sub Procedures, Part II
5.4 Program Design
Function: Int
Example: Int(2.6) is 2
Input: number
Output: number
Function: Math.Round
Example: Math.Round(1.23, 1) is 1.2
Input: number, number
Output: number
© 2017 Pearson Education, Inc.
Hoboken, NJ. All rights reserved.
Some Built-In Functions
(continued)
Function: Chr
Example: Chr(65) is A
Input: number
Output: string
Function: Asc
Example: Asc("Apple") is 65
Input: string
Output: number
© 2017 Pearson Education, Inc.
Hoboken, NJ. All rights reserved.
Function Procedures
txtTempF
txtTempC
txtFullName
txtFirstName
txtWage
txtHours
txtEarnings
Sum(2, 3)
arguments
parameters
Sub DisplaySum(num1 As Double, num2 As Double)
DisplaySum(2, 3)
DisplaySum(4, 6)
DisplaySum(7, 8)
Output:
The sum of 2 and 3 is 5.
The sum of 4 and 6 is 10
The sum of 7 and 8 is 15.
Sub DescribeTask()
lstBox.Items.Clear()
lstBox.Items.Add("This program displays")
lstBox.Items.Add("the name and population")
lstBox.Items.Add("of a state.")
End Sub
• Passing by Value
• Passing by Reference
• Sub Procedures That Return a Single
Value
• Scope and Lifetime of Variables and
Constants
• Debugging
Output: 4
© 2017 Pearson Education, Inc.
Hoboken, NJ. All rights reserved.
Same Example: n num
Public Sub btnOne_Click (...) Handles _
btnOne.Click
Dim num As Double = 4
Triple(num)
txtBox.Text = CStr(num)
End Sub
Sub Triple(num As Double)
num = 3 * num
End Sub
Output: 4
© 2017 Pearson Education, Inc.
Hoboken, NJ. All rights reserved.
Passing by Reference
Output: 12
© 2017 Pearson Education, Inc.
Hoboken, NJ. All rights reserved.
Example: num n
Private Sub btnOne_Click(...) Handles _
btnOne_Click
Dim n As Double = 4
Triple(n)
txtBox.Text = CStr(n)
End Sub
Sub Triple(ByRef num As Double)
num = 3 * num
End Sub
• Top-Down Design
• Structured Programming
• Advantages of Structured Programming
• Object-Oriented Programming