SlideShare a Scribd company logo
1 of 27
Microsoft Visual Basic 2005
BASICS
Lesson 10
Do Loops
Microsoft Visual Basic 2005 BASICS 2
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.
Microsoft Visual Basic 2005 BASICS 3
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
Microsoft Visual Basic 2005 BASICS 4
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.
Microsoft Visual Basic 2005 BASICS 5
Using Do While
 Do While loop
 Repeats a block of code as long as a
condition remains True
 Syntax example
Microsoft Visual Basic 2005 BASICS 6
Using Do While (cont.)
Microsoft Visual Basic 2005 BASICS 7
Using Do Until
 Do Until loop
 Repeats a block of code until a condition is
no longer True
 Syntax example
Microsoft Visual Basic 2005 BASICS 8
Using Do Until (cont.)
Microsoft Visual Basic 2005 BASICS 9
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
Microsoft Visual Basic 2005 BASICS 10
Choosing Do While or Do
Until (cont.)
Microsoft Visual Basic 2005 BASICS 11
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
Microsoft Visual Basic 2005 BASICS 12
Using the InputBox Function
(cont.)
Microsoft Visual Basic 2005 BASICS 13
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.
Microsoft Visual Basic 2005 BASICS 14
Using the InputBox Function
within a Do Until Loop (cont.)
Microsoft Visual Basic 2005 BASICS 15
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
Microsoft Visual Basic 2005 BASICS 16
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
Microsoft Visual Basic 2005 BASICS 17
Event Procedure Problems
(cont.)
Microsoft Visual Basic 2005 BASICS 18
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
Microsoft Visual Basic 2005 BASICS 19
Event Procedure Solutions
(cont.)
Microsoft Visual Basic 2005 BASICS 20
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
Microsoft Visual Basic 2005 BASICS 21
Event Procedure Solutions
(cont.)
Microsoft Visual Basic 2005 BASICS 22
Using Nested Loops
 Like If statements, loops may be
nested.
 It is not uncommon to need a loop within
a loop.
Microsoft Visual Basic 2005 BASICS 23
Summary
 Much of the work a computer does is
repeated many times. This repetition in
programs is accomplished using loops.
Microsoft Visual Basic 2005 BASICS 24
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.
Microsoft Visual Basic 2005 BASICS 25
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.
Microsoft Visual Basic 2005 BASICS 26
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.
Microsoft Visual Basic 2005 BASICS 27
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.

More Related Content

Viewers also liked

Chapter 3 — Program Design and Coding
Chapter 3 — Program Design and Coding Chapter 3 — Program Design and Coding
Chapter 3 — Program Design and Coding francopw
 
A Detailed Introduction: American Accent Training with Language~Loops
A Detailed Introduction: American Accent Training with Language~Loops A Detailed Introduction: American Accent Training with Language~Loops
A Detailed Introduction: American Accent Training with Language~Loops Lang Looper
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Designfrancopw
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computersimran153
 

Viewers also liked (6)

Select case
Select caseSelect case
Select case
 
Chapter 3 — Program Design and Coding
Chapter 3 — Program Design and Coding Chapter 3 — Program Design and Coding
Chapter 3 — Program Design and Coding
 
A Detailed Introduction: American Accent Training with Language~Loops
A Detailed Introduction: American Accent Training with Language~Loops A Detailed Introduction: American Accent Training with Language~Loops
A Detailed Introduction: American Accent Training with Language~Loops
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
 
Introduction to VB.NET - UP SITF
Introduction to VB.NET - UP SITFIntroduction to VB.NET - UP SITF
Introduction to VB.NET - UP SITF
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
 

Similar to Ppt lesson 10

Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netJaya Kumari
 
Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0William Munn
 
CMIS 102 Entire Course NEW
CMIS 102 Entire Course NEWCMIS 102 Entire Course NEW
CMIS 102 Entire Course NEWshyamuopuop
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
Csc153 chapter 05
Csc153 chapter 05Csc153 chapter 05
Csc153 chapter 05PCC
 
Book HH- vb2008me preview
Book   HH- vb2008me previewBook   HH- vb2008me preview
Book HH- vb2008me previewSatya Harish
 
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersSwift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersAzilen Technologies Pvt. Ltd.
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comStephenson22
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comWilliamsTaylorza48
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
Caliburn.micro
Caliburn.microCaliburn.micro
Caliburn.microbwullems
 
MOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docx
MOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docxMOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docx
MOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docxraju957290
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
COBOL deployment to .NET or JVM
COBOL deployment to .NET or JVMCOBOL deployment to .NET or JVM
COBOL deployment to .NET or JVMMicro Focus
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.comHarrisGeorg12
 

Similar to Ppt lesson 10 (20)

While and For Loops
While and For LoopsWhile and For Loops
While and For Loops
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0Legacy Dependency Kata v2.0
Legacy Dependency Kata v2.0
 
CMIS 102 Entire Course NEW
CMIS 102 Entire Course NEWCMIS 102 Entire Course NEW
CMIS 102 Entire Course NEW
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
Csc153 chapter 05
Csc153 chapter 05Csc153 chapter 05
Csc153 chapter 05
 
Book HH- vb2008me preview
Book   HH- vb2008me previewBook   HH- vb2008me preview
Book HH- vb2008me preview
 
Swift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for DevelopersSwift 2.0: Apple’s Advanced Programming Platform for Developers
Swift 2.0: Apple’s Advanced Programming Platform for Developers
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Caliburn.micro
Caliburn.microCaliburn.micro
Caliburn.micro
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
MOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docx
MOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docxMOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docx
MOAC 70-687 - Configuring Windows 8.1 MLO WorksheetLab 10Confi.docx
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Vb 6ch123
Vb 6ch123Vb 6ch123
Vb 6ch123
 
COBOL deployment to .NET or JVM
COBOL deployment to .NET or JVMCOBOL deployment to .NET or JVM
COBOL deployment to .NET or JVM
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.com
 

More from Linda Bodrie

More from Linda Bodrie (15)

Ppt lesson 12
Ppt lesson 12Ppt lesson 12
Ppt lesson 12
 
Ppt lesson 09
Ppt lesson 09Ppt lesson 09
Ppt lesson 09
 
Ppt lesson 08
Ppt lesson 08Ppt lesson 08
Ppt lesson 08
 
Ppt lesson 07
Ppt lesson 07Ppt lesson 07
Ppt lesson 07
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Ppt lesson 05
Ppt lesson 05Ppt lesson 05
Ppt lesson 05
 
Lesson 5 PP
Lesson 5 PPLesson 5 PP
Lesson 5 PP
 
Lesson 4 PowerPoint
Lesson 4 PowerPointLesson 4 PowerPoint
Lesson 4 PowerPoint
 
Ppt lesson 03
Ppt lesson 03Ppt lesson 03
Ppt lesson 03
 
Les 02 1
Les 02 1Les 02 1
Les 02 1
 
PowerPoint Lesson 2
PowerPoint Lesson 2PowerPoint Lesson 2
PowerPoint Lesson 2
 
Ppt lesson 01
Ppt lesson 01Ppt lesson 01
Ppt lesson 01
 
PowerPoint Lesson 1
PowerPoint Lesson 1PowerPoint Lesson 1
PowerPoint Lesson 1
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Ppt lesson 10

  • 1. Microsoft Visual Basic 2005 BASICS Lesson 10 Do Loops
  • 2. Microsoft Visual Basic 2005 BASICS 2 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.
  • 3. Microsoft Visual Basic 2005 BASICS 3 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
  • 4. Microsoft Visual Basic 2005 BASICS 4 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.
  • 5. Microsoft Visual Basic 2005 BASICS 5 Using Do While  Do While loop  Repeats a block of code as long as a condition remains True  Syntax example
  • 6. Microsoft Visual Basic 2005 BASICS 6 Using Do While (cont.)
  • 7. Microsoft Visual Basic 2005 BASICS 7 Using Do Until  Do Until loop  Repeats a block of code until a condition is no longer True  Syntax example
  • 8. Microsoft Visual Basic 2005 BASICS 8 Using Do Until (cont.)
  • 9. Microsoft Visual Basic 2005 BASICS 9 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
  • 10. Microsoft Visual Basic 2005 BASICS 10 Choosing Do While or Do Until (cont.)
  • 11. Microsoft Visual Basic 2005 BASICS 11 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
  • 12. Microsoft Visual Basic 2005 BASICS 12 Using the InputBox Function (cont.)
  • 13. Microsoft Visual Basic 2005 BASICS 13 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.
  • 14. Microsoft Visual Basic 2005 BASICS 14 Using the InputBox Function within a Do Until Loop (cont.)
  • 15. Microsoft Visual Basic 2005 BASICS 15 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
  • 16. Microsoft Visual Basic 2005 BASICS 16 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
  • 17. Microsoft Visual Basic 2005 BASICS 17 Event Procedure Problems (cont.)
  • 18. Microsoft Visual Basic 2005 BASICS 18 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
  • 19. Microsoft Visual Basic 2005 BASICS 19 Event Procedure Solutions (cont.)
  • 20. Microsoft Visual Basic 2005 BASICS 20 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
  • 21. Microsoft Visual Basic 2005 BASICS 21 Event Procedure Solutions (cont.)
  • 22. Microsoft Visual Basic 2005 BASICS 22 Using Nested Loops  Like If statements, loops may be nested.  It is not uncommon to need a loop within a loop.
  • 23. Microsoft Visual Basic 2005 BASICS 23 Summary  Much of the work a computer does is repeated many times. This repetition in programs is accomplished using loops.
  • 24. Microsoft Visual Basic 2005 BASICS 24 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.
  • 25. Microsoft Visual Basic 2005 BASICS 25 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.
  • 26. Microsoft Visual Basic 2005 BASICS 26 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.
  • 27. Microsoft Visual Basic 2005 BASICS 27 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.