Download presentation
Presentation is loading. Please wait.
Published byQuentin Shields Modified over 9 years ago
1
General Procedures Chapter 4
2
Different Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular Design (not on test)
3
Sub Procedures Part 1 Sub Procedure - part of a program that performs one or more related tasks, has its own name, is written as a separate part of the program. Private Sub ProcedureName() statements End Sub
4
Example 1 pg.143 Private Sub cmdAdd_Click() Dim num1 as single, num2 as single picResult.cls Call ExplainPurpose picResult.Print num1 = 2 num2 = 3 picResult.Print “The sum of”; num1; “and”; num2; “is”; num1 + num2 End Sub Private Sub ExplainPurpose() picResult.Print “This program displays a sentence” picResult.Print “Identifying two numbers and their sum.” End Sub
5
Example 2, pg.144 Private Sub cmdAdd_Click() Dim num1 as single, num2 as single picResult.cls Call ExplainPurpose picResult.Print Call Add(2,3) End Sub Private Sub Add(num1 as Single, num2 as Single) picResult.Print “the sum of”; num1; “and”; num2; “is”; num1 + num2 End Sub Private Sub ExplainPurpose() picResult.Print “This program displays a sentence” picResult.Print “Identifying two numbers and their sum.” End Sub
6
Sub Procedures Part II Passing Values Back from Sub Procedures passed by reference passed by value - use this method when you want to ensure the variable will retain its original value when the Sub terminates In the Call statement, enclose the variable with an extra parentheses…..Call Triple((amt)) Use ByVal statement…. Private Sub Triple(By Val num as single) NOTE: Look at Practice Problem 3 on page 170
7
Function Procedures Built-in Visual Basic Function Format, Val, Int, Chr, Len, Mid, InStr (pg 178) User-defined functions Functions that you create and declare Private Function FunctionName (var1 as Type1,…..) as dataType statements FunctionName = expression End Function
8
Function Example 1, pg 179 Private Sub cmdConvert_Click() picTempC.cls picTemC.Print FtoC(val(txtTempF.Text)) End Sub Private Function FtoC(t as Single) as Single FtoC = (5 / 9) * (t - 32) End Function NOTE: Look at Practice Problem 2 on page 185
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.