1 / 16

Clearly Visual Basic: Programming with Visual Basic 2008

Clearly Visual Basic: Programming with Visual Basic 2008. Chapter 18 Talk To Me. Objectives. Explain the difference between a sub procedure and a function procedure Create a function procedure Invoke a function procedure. What’s the Answer?. Function procedure

alta
Download Presentation

Clearly Visual Basic: Programming with Visual Basic 2008

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. Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 18 Talk To Me

  2. Objectives • Explain the difference between a sub procedure and a function procedure • Create a function procedure • Invoke a function procedure Clearly Visual Basic: Programming with Visual Basic 2008

  3. What’s the Answer? • Function procedure • Returns a value after performing its assigned task • Can receive information either by value or by reference • Information it receives is listed in the parameterList in the header • Sub procedure • Does not return a value Clearly Visual Basic: Programming with Visual Basic 2008

  4. Clearly Visual Basic: Programming with Visual Basic 2008

  5. Clearly Visual Basic: Programming with Visual Basic 2008

  6. What’s the Answer? (continued) • After creating a function: • You can invoke it from one or more places in an application’s code • To invoke a function: • Include the function’s name, along with any arguments, in a statement • Usually the statement that invokes a function will assign the function’s return value to a variable • May also use the return value in a calculation Clearly Visual Basic: Programming with Visual Basic 2008

  7. Clearly Visual Basic: Programming with Visual Basic 2008

  8. Clearly Visual Basic: Programming with Visual Basic 2008

  9. Price Calculator Application • Figure 18-3 • Shows the Price Calculator application’s user interface • The variables in a function’s header • Have procedure scope Clearly Visual Basic: Programming with Visual Basic 2008

  10. Clearly Visual Basic: Programming with Visual Basic 2008

  11. Revisiting the Total Due Calculator Application Figure 18-8 Shows interface for the Total Due Calculator application from Chapter 17 Figure 18-9 Shows the code entered in both the AssignDiscount sub procedure and btnCalc control’s Click event procedure in Chapter 17 Most programmers: Pass a variable by reference only when a procedure needs to produce more than one result Clearly Visual Basic: Programming with Visual Basic 2008

  12. Clearly Visual Basic: Programming with Visual Basic 2008

  13. Clearly Visual Basic: Programming with Visual Basic 2008

  14. Clearly Visual Basic: Programming with Visual Basic 2008

  15. Summary • You can create your own function procedures, called functions • Return statement • Appears as the last statement in a function • Invoke a function by: • Including the function’s name, along with any arguments, in a statement Clearly Visual Basic: Programming with Visual Basic 2008

  16. Summary (continued) • The statement that invokes a function may: • Assign the return value to a variable • Use the return value in a calculation • Display the return value • The following have procedure scope • Variables that appear in a function header’s parameterList • In most cases: • Better to use a function rather than a sub procedure that passes a variable by reference Clearly Visual Basic: Programming with Visual Basic 2008

More Related