Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Ppt lesson 10

on

  • 1,617 views

 

Statistics

Views

Total Views
1,617
Views on SlideShare
1,462
Embed Views
155

Actions

Likes
0
Downloads
20
Comments
1

2 Embeds 155

http://thsbonovb.wikispaces.com 147
http://bono71.blogspot.com 8

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • poot.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ppt lesson 10 Ppt lesson 10 Presentation Transcript

  • Microsoft Visual Basic 2005 BASICS Lesson 10 Do Loops
  • Objectives
    • Explain what a loop is.
    • Use the Do While and Do Until loops.
    • Use the InputBox function.
    • Use the Application.DoEvents statement.
    • Use nested loops.
  • What Are Loops?
    • Statement repetition is accomplished by a loop.
    • Iteration structure
      • The code required to create a loop
    • Loops
      • Do While
      • Do Until
      • For
    View slide
  • Using the Do Loops
    • Knowing which of the Do loops to use is just a matter of experience.
    • Both types of Do loops rely on a condition to be either True or False.
    View slide
  • Using Do While
    • Do While loop
      • Repeats a block of code as long as a condition remains True
    • Syntax example
  • Using Do While (cont.)
  • Using Do Until
    • Do Until loop
      • Repeats a block of code until a condition is no longer True
    • Syntax example
  • Using Do Until (cont.)
  • Choosing Do While or Do Until
    • Primary difference
      • A Do While loop tests the condition at the top of the loop.
      • The Do Until loop tests the condition at the bottom of the loop.
    • Do While loop
      • Should only be used if you are sure that you want the loop to execute at least once
  • Choosing Do While or Do Until (cont.)
  • Using the InputBox Function
    • InputBox function
      • The opposite of the MsgBox function
      • Displays a window to ask the user for input
    • Using the InputBox function
      • Supply two strings
        • The text that will prompt the user
        • The title for the window’s title bar
  • Using the InputBox Function (cont.)
  • Using the InputBox Function within a Do Until Loop
    • The InputBox function can be used inside a Do Until loop.
      • To repeatedly ask the user for data until a specified condition is met
    • Place a call to the InputBox function inside a Do Until loop.
  • Using the InputBox Function within a Do Until Loop (cont.)
  • Potential Event Procedure Problems and Solutions
    • When an event is triggered
      • An event procedure is executed to handle the event
      • Executing an event procedure takes some time.
        • Can cause problems
  • Event Procedure Problems
    • Long event procedures
      • Includes a loop that processes thousands of instructions
      • Program is unresponsive to other events
    • Endless loops
      • Condition to stop the loop never becomes True
      • Usually a programming error
  • Event Procedure Problems (cont.)
  • Event Procedure Solutions
    • Application.DoEvents subroutine
      • Allows computer to process other events even though the current event procedure is not yet complete
    • Add it to a loop that may occupy a lot of the computer’s time.
    • Introduces the potential for repetitive Click event procedures
  • Event Procedure Solutions (cont.)
  • Event Procedure Solutions (cont.)
    • Preventing repetitive Click event procedures
      • Disable the button at the beginning of the event procedure.
        • Prevents the user from clicking the button again until the event processing is completed
  • Event Procedure Solutions (cont.)
  • Using Nested Loops
    • Like If statements, loops may be nested.
    • It is not uncommon to need a loop within a loop.
  • Summary
    • Much of the work a computer does is repeated many times. This repetition in programs is accomplished using loops.
  • Summary (cont.)
    • A Do loop condition applies a test to achieve either a True or False result. A Do While loop tests the condition at the top of the loop and repeats a group of statements while a certain condition is True. A Do Until loop tests the condition at the bottom of the loop and repeats a group of statements until a certain condition becomes True. The code in a Do Until loop is always executed at least once.
  • Summary (cont.)
    • The InputBox function creates a window that prompts the user for input. To use the InputBox function, you supply the text for the prompt, the title for the window’s title bar, and the optional default text for the text box.
    • Sometimes, long event procedures can make a program unresponsive to other events.
  • Summary (cont.)
    • An endless loop is a loop in which the condition that stops the loop is never met. Clicking the Break All button in the IDE will pause a program with an endless loop and will highlight the code where the program stopped.
  • Summary (cont.)
    • An Application.DoEvents subroutine allows the program to process other events while an event procedure is executing.
    • Loops can be nested in the same way that If statements are nested.