1 / 29

Clearly Visual Basic: Programming with Visual Basic 2008

Clearly Visual Basic: Programming with Visual Basic 2008. Chapter 13 How Long Can This Go On?. Objectives. Write a pretest loop using the Do…Loop statement Utilize counter and accumulator variables Refresh the screen Delay program execution

clayrandall
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 13 How Long Can This Go On?

  2. Objectives • Write a pretest loop using the Do…Loop statement • Utilize counter and accumulator variables • Refresh the screen • Delay program execution • Show a pretest loop in both pseudocode and a flowchart • Display a dialog box using the InputBox function Clearly Visual Basic: Programming with Visual Basic 2008

  3. Over and Over Again • Repetition structure (loop) • Used to process one or more program instructions repeatedly, until some condition is met • Can be either a pretest loop or a posttest loop • Pretest loop • Loop condition is evaluated before the instructions within the loop are processed • Posttest loop • Evaluation occurs after the instructions within the loop are processed Clearly Visual Basic: Programming with Visual Basic 2008

  4. Clearly Visual Basic: Programming with Visual Basic 2008

  5. Over and Over Again (continued) • Figure 13-2 • Shows the modified problem specification along with the modified algorithm • Figure 13-3 • Shows another problem specification and algorithm involving Rob • Figures 13-4 and 13-5 • Shows a modified version of the previous problem specification Clearly Visual Basic: Programming with Visual Basic 2008

  6. 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. Clearly Visual Basic: Programming with Visual Basic 2008

  10. The Do … Loop Statement Do…Loop statement Used to code both a pretest loop and a posttest loop Figure 13-6 Shows syntax of the Do…Loop statement Keyword While Indicates that the loop instructions should be processed while the condition is true Keyword Until Indicates that the loop instructions should be processed until the condition becomes true Clearly Visual Basic: Programming with Visual Basic 2008

  11. Clearly Visual Basic: Programming with Visual Basic 2008

  12. Clearly Visual Basic: Programming with Visual Basic 2008

  13. The Do … Loop Statement (continued) • intNumber variable • Called a counter variable • Counter variables • Always numeric variables • Typically assigned a beginning value of either 0 or 1, depending on the value required by the application • Updating (incrementing) • Adding a number to the value stored in the counter variable Clearly Visual Basic: Programming with Visual Basic 2008

  14. Clearly Visual Basic: Programming with Visual Basic 2008

  15. My Dream Car-Version 1 Application • Figure 13-8 • Shows the interface for the My Dream Car-Version 1 application • Refresh method • Will ensure that any code appearing before it that affects the interface’s appearance is processed • Syntax: Me.Refresh() • Sleep method • Used todelay program execution • Syntax • System.Threading.Thread.Sleep(milliseconds) Clearly Visual Basic: Programming with Visual Basic 2008

  16. Clearly Visual Basic: Programming with Visual Basic 2008

  17. Flowcharting the Click Me Button’s Event Procedure • Figure 13-11 • Shows flowchart for the Click Me button’s Click event procedure • You mark the flowline leading to the true path with a “T” (for True) • You mark the flowline leading to the false path with an “F” (for False) Clearly Visual Basic: Programming with Visual Basic 2008

  18. Clearly Visual Basic: Programming with Visual Basic 2008

  19. My Dream Car-Version 2 Application • The lblMessage control’s Visible property • Set to True in the Properties window • The picCar control’s Visible property is set to False • Figure 13-12 • Shows the algorithm for the Click Me button’s Click event procedure Clearly Visual Basic: Programming with Visual Basic 2008

  20. Clearly Visual Basic: Programming with Visual Basic 2008

  21. The Sales Express Application • Accumulator variable • Numeric variable used for accumulating something • Assigned a value outside the loop • Updated within the loop • Incremented by an amount that varies Clearly Visual Basic: Programming with Visual Basic 2008

  22. Clearly Visual Basic: Programming with Visual Basic 2008

  23. Clearly Visual Basic: Programming with Visual Basic 2008

  24. The InputBox Function • Displays one of the standard dialog boxes available in Visual Basic • Empty string • Represented by the String.Empty constant • Figure 13-16 • Shows basic syntax of the InputBox function Clearly Visual Basic: Programming with Visual Basic 2008

  25. Clearly Visual Basic: Programming with Visual Basic 2008

  26. The InputBox Function (continued) • Figure 13-18 • Shows a sample testing chart for the Sales Express application • Runtime error • Occurs while an application is running • Before using a variable as the divisor in an expression: • Verify that the variable does not contain the number 0 Clearly Visual Basic: Programming with Visual Basic 2008

  27. Clearly Visual Basic: Programming with Visual Basic 2008

  28. Summary • Use a repetition structure, or loop • To repeatedly process one or more program instructions • Loop • Can be either a pretest loop or a posttest loop • Do…Loop statement • Can be used to code a pretest loop • Counter and accumulator variables • Should be assigned a value outside the loop, but updated within the loop Clearly Visual Basic: Programming with Visual Basic 2008

  29. Summary (continued) • Loop condition • Represented by a diamond in a flowchart • Priming read • Gets only the first input item from the user • InputBox function • Can be used to display a dialog box that contains a message, an OK button, a Cancel button, and an input area • If a variable is used as the divisor in an expression: • Always verify that the variable does not contain the number 0 Clearly Visual Basic: Programming with Visual Basic 2008

More Related