1 / 39

Outline 13.1 Test-Driving the Enhanced Wage Calculator Application 13.2 Classes and Procedures

Tutorial 13 – Enhancing the Wage Calculator Application Introducing Function Procedures and Sub Procedures. Outline 13.1 Test-Driving the Enhanced Wage Calculator Application 13.2 Classes and Procedures 13.3 Function Procedures

Télécharger la présentation

Outline 13.1 Test-Driving the Enhanced Wage Calculator Application 13.2 Classes and 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. Tutorial 13 – Enhancing the Wage Calculator ApplicationIntroducing Function Procedures and Sub Procedures Outline 13.1 Test-Driving the Enhanced Wage Calculator Application 13.2 Classes and Procedures 13.3FunctionProcedures 13.4 Using Sub Procedures in the Wage Calculator Application 13.5 Using the Debugger: Debug Toolbar 13.6 Wrap-Up

  2. Objectives • In this tutorial, you will learn to: • Construct applications modularly from pieces called procedures. • Work with “built-in” procedures. • Distinguish between Function procedures and Sub procedures, and determine when each should be used. • Create your own Function procedures and Sub procedures.

  3. 13.1 Test-Driving the Enhanced Wage Calculator Application

  4. 13.1 Test-Driving the Enhanced Wage Calculator Application Figure 13.1 WageCalculator executing. • Load the Wage Calculator application • Debug > Start • Set Hourly wage:TextBox to 10 • Set Weekly hours:TextBox to 45 • Click CalculateButton

  5. 13.2 Classes and Procedures • Classes • Programmer defined or predefined • Reusing code • Procedures • Function procedures • Sub procedures

  6. Procedure Description Example Math.Max(x, y) Math.Max( 2.3 , 12.7 ) 12.7 Returns the larger value is x y of and Math.Max( - 2.3 , - 12.7 ) - 2.3 is Math.Min(x, y) Math.Min( 2.3 , 12.7 ) 2.3 Returns the smaller value of is x and y Math.Min( - 2.3 , - 12.7 ) - 12.7 is Ma th.Sqrt(x) x Math.Sqrt( 9 ) 3.0 Returns the square root of is Math.Sqrt( 2 ) 1.4142135623731 is Pmt(x, y, z) Pmt( 0.05 , 12 , - 4000 ) Calculates loan payments where is x y 451.301640083261 specifies the interest rate, specifies the number of payment z periods and specifies the principal value of the l oan Val(x) x Val( “5” ) 5 Returns a numeric value for is Val( “5a8” ) 5 is Val( “a5” ) 0 is .Format(x, y) String String String .Form at( “{0:C}” , 1.23 ) Returns values where is x y “$1.23” is a format string, and is a value to be formatted as a String 13.2 Classes and Procedures Figure 13.2 Some predefined Visual Basic .NET procedures.

  7. 13.3FunctionProcedures Figure 13.3 Hypotenuse Calculator GUI.

  8. 13.3 FunctionProcedures • View code for HypotenuseCalculator • Notice the six variables • Three are side lengths • Three are side lengths squared • If…Then…ElseStatement • Checks validity • Calculates hypotenuse

  9. Lengths for sides A, B, and hypotenuse Square of lengths for sides A, B, and hypotenuse Message dialog displays if negative values (or zero) are entered 13.3 FunctionProcedures Figure 13.4Hypotenuse Calculator template code.

  10. 13.3FunctionProcedures • Procedure definition • Procedure header • Begins with Function • Followed by procedure name and variable declaration • Parameter list • Variables used only within function procedure • Return type • Procedure Body • End Function

  11. Function procedure header End Functionkeywords mark the end of aFunctionprocedure 13.3FunctionProcedures Figure 13.5FunctionprocedureSquare.

  12. Calculating squares by using the ^ operator 13.3FunctionProcedures Figure 13.6 Square procedure definition

  13. 13.3FunctionProcedures • Invoking a procedure • Procedure call • Procedure name followed by arguments inside parentheses • Example: Square(dblSideA) • Parameter Info window • When the procedure is complete, the caller, or calling procedure, regains control.

  14. Calling procedure Square 13.3FunctionProcedures Figure 13.7Invoking procedure Square.

  15. Parameter Info window 13.3FunctionProcedures Figure 13.8 Parameter Info window.

  16. 13.3FunctionProcedures Figure 13.9 Completing the btnCalculate_Click event handler.

  17. 13.3FunctionProcedures Figure 13.10 Hypotenuse Calculator application executing. • Load the Hypotenuse Calculator application • Debug > Start • Set Length of Side A:TextBox to 3 • Set Length of Side B:TextBox to 4 • Click the Calculate HypotenuseButton

  18. TextBoxes used to input three values 13.3FunctionProcedures Figure 13.11 Maximum application in design view.

  19. Calling a procedure that has not yet been defined is an error 13.3FunctionProcedures Figure 13.12Invoking Function procedure Maximum.

  20. Empty Functionprocedure Maximum 13.3FunctionProcedures Figure 13.13 MaximumFunction procedure.

  21. Calling Math.Max to determine the maximum of two values 13.3FunctionProcedures Figure 13.14 Math.Max returns the larger of its two arguments.

  22. 13.3FunctionProcedures Figure 13.15 Maximum application executing.

  23. 13.4 Using Sub Procedures in the Wage Calculator Application • Sub procedures • Definition is same as a Function procedure, but the keyword Sub replaces Function • No return value or return type

  24. Call to DisplayPay 13.4 Using Sub Procedures in the Wage Calculator Application Figure 13.16 btnCalculate_Click calls DisplayPay.

  25. DisplayPay calculates and displays the user’s gross earnings 13.4 Using Sub Procedures in the Wage Calculator Application Figure 13.17 Sub procedure DisplayPay definition.

  26. 13.4 Using Sub Procedures in the Wage Calculator Application Figure 13.18 Function procedure CheckOverTime definition.

  27. Call to procedure CheckOvertime 13.4 Using Sub Procedures in the Wage Calculator Application Figure 13.19 DisplayPay calls Function procedure CheckOvertime.

  28. WageCalculator2.vb(1 of 3)

  29. WageCalculator2.vb(2 of 3)

  30. WageCalculator2.vb(3 of 3)

  31. Step into Step out Continue Stop debugging Step over 13.5 Using the Debugger: Debug Toolbar Figure 13.21 Debug Toolbar. • Debug toolbar • Controls the debugging process • View > Toolbars > Debug

  32. Debug toolbar Breakpoint set on a line containing a procedure call 13.5 Using the Debugger: Debug Toolbar Figure 13.22 Setting a breakpoint. • Set breakpoints by clicking in the margin indicator bar

  33. Next statement to execute is a procedure call 13.5 Using the Debugger: Debug Toolbar Figure 13.23 Statement calls procedure DisplayPay.

  34. 13.5 Using the Debugger: Debug Toolbar • Step Into • Executes next statement in application • If next statement is procedure call, statements will be executed step by step • Step Out • Returns control to calling procedure • Used only after a procedure has been stepped into • Step Over • Executes next statement in application • If next statement is procedure call, procedure will be fully executed

  35. Control is transferred to the procedure definition 13.5 Using the Debugger: Debug Toolbar Figure 13.24 Using the debug toolbar’s Step Into Button.

  36. Procedure CheckOverTime will be executed without stepping into it when the Step Over Button is clicked 13.5 Using the Debugger: Debug Toolbar Figure 13.25 Using the debug toolbar’s Step Over Button.

  37. 13.5 Using the Debugger: Debug Toolbar Figure 13.25 Using the debug toolbar’s Step Over Button again.

  38. 13.5 Using the Debugger: Debug Toolbar • Continue • Continues executing code • Does not stop until next break point or end of event handler • Stop • Ends debugging session

  39. 13.5 Using the Debugger: Debug Toolbar Figure 13.25 Using the debug toolbar’s Continue Button.

More Related