Click to edit Master title - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Click to edit Master title

Description:

Title: Click to edit Master title Author: Richard Chrisman Last modified by: Mirella Misiaszek Created Date: 10/23/2003 2:16:34 PM Document presentation format – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 36
Provided by: RichardC72
Category:
Tags: click | edit | master | overtime | title

less

Transcript and Presenter's Notes

Title: Click to edit Master title


1
1
2
Objectives
  • Explain the difference between a Sub procedure
    and a Function procedure
  • Create a Sub procedure
  • Create a procedure that receives information
    passed to it
  • Explain the difference between passing data by
    value and passing data by reference
  • Create a Function procedure

3
Procedure
  • Procedure a block of program code that performs
    a specific task
  • Function Procedure
  • Returns a value after performing its assigned
    task
  • Sub Procedure
  • Completes the task but does not return a value

4
Sub Procedures
  • Event procedure
  • Associated with a specific object and event
  • Example button click event
  • Independent Sub procedure
  • A collection of code that can be invoked from one
    or more places in an application
  • Processed only when called (invoked) from code
  • Invoke Sub using a Call statement from another
    procedure

5
Sub Procedures (continued)
  • Private indicates procedure can only be used by
    other procedures in the current form
  • Sub keyword identifies procedure as a Sub
    Procedure
  • procedurename - name given to procedure
  • Naming rules same as for naming variables
  • parameterlist - optional set of memory locations
    referred to as parameters
  • ByVal, ByRef specify how parameter is passed

6
Sub Procedures (continued)
7
Sub Procedures (continued)
8
Gladis Antiques Application
  • Manager wants an application to calculate
    employees regular pay, overtime pay, and gross
    pay
  • Employees are paid on hourly basis with time and
    one-half for overtime
  • Sub ClearLabels() will be used to clear display
    labels on form for 3 pay amounts

9
Gladis Antiques Application (continued)
10
Gladis Antiques Application (continued)
11
Gladis Antiques Application (continued)
12
Including Parameters in an Independent Sub
Procedure
  • Call statement has an optional argumentlist
  • Comma separated list of arguments passed to
    procedure being called
  • Argumentlist must agree with number of parameters
    listed in parameterlist in the procedure header
  • Data type and position of each parameter must
    agree with data type and position of
    corresponding argument

13
Passing Variables
  • Pass by value
  • Use keyword ByVal
  • Passes contents of variable to the parameter in
    receiving procedure but not memory location
  • Cannot change contents of passing variable
  • Pass by reference
  • Use keyword ByRef
  • Passes memory address of variable to the
    receiving procedure
  • Contents of variable can be changed within
    receiving procedure

14
Passing Variables by Value
15
Passing Variables by Value (continued)
16
Passing Variables by Reference
17
Passing Variables by Reference (continued)
18
Passing Variables by Reference (continued)
19
Function Procedures
  • Block of code that performs a task and returns a
    value after completing that task
  • Function header has keyword Function instead of
    Sub
  • Header has As datatype clause that specifies
    data type of value returned by the function
  • As Decimal - returns a decimal number
  • As String - returns a string
  • Return statement alerts computer that function
    has completed task and returns the value
    contained in its expression

20
Function Procedures (continued)
21
The Pine Lodge Application
  • Owner wants application to calculate new hourly
    pay given current pay rate and raise rate
  • Application demonstrates use of function
    procedure GetNewPay
  • Current pay rate and raise rate passed by value
    as parameters
  • New hourly pay returned by function

22
The Pine Lodge Application (continued)
23
The Pine Lodge Application (continued)
24
The Pine Lodge Application (continued)
25
Programming Example Rainfall Application
  • Application allows user to enter monthly rainfall
    amounts for previous year
  • Calculates and displays the total rainfall amount
    and average rainfall amount

26
TOE Chart
27
User Interface
28
Objects, Properties, and Settings
29
Tab Order
30
Pseudocode
  • btnExit Click event procedure
  • 1. Close the application
  • btnCalc Click event procedure
  • 1. call the CalctotalAndAverage procedure to
    calculate the total and average rainfall
  • 2. display the total and average rainfall
    amounts in labels

31
Pseudocode (continued)
  • CalcTotalAndAverage procedure
  • 1. initialize the month counter to 1
  • 2. repeat while amount is numeric
  • get a rainfall amount
  • if rainfall amount is numeric
  • add rainfall amount to total rainfall
    accumulator
  • add 1 to the month counter
  • else
  • display message informing user to enter a
    number
  • end if
  • end repeat
  • 3. calculate the average rainfall total
    rainfall / 12

32
Code
33
Code (continued)
34
Summary
  • Procedures allow reuse of code throughout an
    application and allow programmer teamwork on
    large and complex applications
  • Function procedures return a value, Sub
    procedures do not
  • Independent Sub procedures and Functions are not
    associated with any specific object or event
  • Use Call statement to invoke an Independent sub
    procedure

35
Summary (continued)
  • Number of arguments and data types must match in
    argumentlist and parameterlist
  • ByVal keyword passes contents of variable
  • Value of variable being passed cannot be changed
    in procedure
  • ByRef keywords passes the memory address
  • Value of variable being pass can be changed in
    procedure
  • Variables in parameterlist have procedure level
    scope
Write a Comment
User Comments (0)
About PowerShow.com