1 / 8

General Procedures

General Procedures. Chapter 4. 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). Sub Procedures Part 1.

lei
Download Presentation

General Procedures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 ExplainPurpose() picResult.Print “This program displays a sentence” picResult.Print “Identifying two numbers and their sum.” End Sub Private Sub Add(num1 as Single, num2 as Single) picResult.Print “the sum of”; num1; “and”; num2; “is”; num1 + num2 End Sub

  6. NOTE: Look at Practice Problem 3 on page 170 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)

  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. NOTE: Look at Practice Problem 2 on page 185 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

More Related