For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.

Slides:



Advertisements
Similar presentations
Programming with Microsoft Visual Basic 2008 Fourth Edition
Advertisements

Programming with Microsoft Visual Basic th Edition
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Programming Logic and Design Eighth Edition
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Objectives In this chapter, you will learn about:
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Chapter 5: Loops and Files.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
5.05 Apply Looping Structures
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
Chapter 12: How Long Can This Go On?
Programming Logic and Design Fifth Edition, Comprehensive
Chapter 4: Loops and Files. The Increment and Decrement Operators  There are numerous times where a variable must simply be incremented or decremented.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 5 Lists, Loops, Validation, and More.
ISAT 252 Visual Basic Repetition. Assignment Should have read Chapter 5 ( ) on loops Do tutorial 5-4.
Chapter 6: The Repetition Structure
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Loops and Files. 5.1 The Increment and Decrement Operators.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Controlling Program Flow with Looping Structures
Unit 6 Repetition Processing Instructor: Brent Presley.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 9: Chapter 5: Slide 1 Unit 9 Do Until and For… Next Loops Chapter 5 Lists,
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Programming Logic and Design Fourth Edition, Comprehensive
Lists, Loops, Validation, and More
Chapter 5: Repetition Structures
JavaScript: Control Statements.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Iteration: Beyond the Basic PERFORM
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Topics Introduction to Repetition Structures
Presentation transcript:

For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5

2 For…Next Loop Ideal for situations that require a counter. Specifically designed to initialize, test, and increment a counter variable. Unlike Do…While and Do…Until loops, For…Next has a specific number of iterations.

Chapter 53 Syntax For Counter = Start to End statementblock Next Counter

Chapter 54 Counter Variable used as a counter. Must be numeric. Variable initialized by programmer. Must appear in For line. Optional, but recommended, in Next line.

Chapter 55 Start Initial value of the counter variable. Must be numeric.

Chapter 56 End Value the counter variable is tested against just prior to each iteration of the loop. Must be numeric.

Chapter 57 Next Counter Marks end of loop. Increments counter automatically.

Chapter 58 Squares Example Find the square of values 1 through 10. Display the value and its square as a string: The square of 2 is 4. Use ToString to convert an integer to a string: strOutput.ToString

Chapter 59 Create this Example (Tutorial 5-7) Initialize counter to 1 Compare counter to 10 Increment counter by 1; Go back to compare counter Body of loop

Chapter 510 Iterations intCountintSquareIterations 00Pre loop 121 ^ ^ ^ ^ ^ 2

Chapter 511 For…Next Process Step 1: Initialize intCount to 1. Step 2: Compare intCount to 10. If intCount is not > 10 go to Step 3. Otherwise, terminate the loop. Step 3: Execute body of loop. Step 4: Increment intCount by 1. Go back to Step 2.

Chapter 512 For…Next Results

Chapter 513 For…Next or Do…Loop For…Next # of iterations can be determined when the loop is entered. Do…Loop Only when # of iterations depends on results inside loop.

Chapter 514 Step Option For counter = start To end Step increment statementblock Next counter Increment: amount to step counter must be numeric Default increment = 1 if not stated

Chapter 515 Step Example (p. 295) Increases x by 10

Chapter 516 Negative Step Amounts Counts backwards by subtracting from counter. If counter >= ending value, execute statementblock. If counter < ending value, exit the loop.

Chapter 517 Negative Step Example Start counter high End counter low Decrease counter

Chapter 518 Particulars Changing the start, end, and step variables inside the For…Next loop do not affect counters since initialization already occurred. Changing the counter variable inside the For…Next loop can cause problems; do not change this variable! (Warning on p. 292)

Chapter 519 Summing Numbers See 1 st example on p Use accumulator to add value of counter variable. Output final accumulated value after the loop is completed. See 2 nd example on p Use input box so that user can specify how many numbers to sum. Use CInt to convert string to integer.

Chapter 520 Exit Loops Exit For Exits a For…Next loop. See example on p Exit Do Exits a Do…Loop.

Chapter 521 Loop Decisions Do While Want loop to repeat as long as test expression is true. Doesn’t loop if false. Write as pretest if you do not want loop to iterate if expression is false from beginning. Write as posttest if want to loop to iterate once. Do Until Want loop to repeat as long as test expression is false. Doesn’t loop if true. Write as pretest if don’t want to loop if test expression is true from beginning. Write as posttest if want loop to iterate at least once. For Next Initializes counter variable to a start value. Increments automatically at the end of the iteration. Loops as long as counter variable is not greater than an end value (or less than end value for decrementing). Use when number of iterations is known upfront.

Chapter 522 Nested Loop Loop inside another loop. Example: Clock with second hand, minute hand, and hour hand Indentation is important for readability!

Chapter 523 Nested Loop Example (pp )

Chapter 524 Clock Example

Chapter 525 Using For…Next Loops for Lists (Figure 7.32 on p. 364)

Chapter 526 Checked List Box Control Variation of a list box Supports all ListBox control properties and methods. Selected property (only 1 at a time) Checked property (multiple can be checked)

Chapter 527 Checked List Box (pp ) Selected: Provo (only) Checked: Layton, Ogden, Park City, Provo

Chapter 528 Copy Checked Items to List Box

Chapter 529 CheckOnClick Property False (default) Click to select Click to check True Click to select & check

Chapter 530 Combo Boxes Read on your own (pp ). Complete Tutorial 5-9 (pp ).

Chapter 531 More Input Validation Review Garbage in  Garbage Out Validates user input to ensure appropriate. Positive value Number not letter Within a range

Chapter 532 Validating Event Triggers just before focus shifts to another control whose CausesValidation property is true. Enables you to write error messages and keep focus to text box instead of shifting focus to another control

Chapter 533 Input Validation Complete Tutorial 5-10 now. Add code for Validating event. Perform software testing by experimenting with different number combinations. Include two GotFocus events to select contents upon focus.

Chapter 534 With…End With (p. 314) Avoid using an object name several times. With txtNum1.SelectionStart = 0.SelectionLength =.Text.Length End With

Chapter 535 ToolTips (aka ScreenTips) Small box that displays when the mouse is over a control. Short description of the control. ToolTip control provides ToolTip property for all controls on a form.

Chapter 536 ToolTip Properties InitialDelay Milliseconds that elapse between mouse over and ToolTip appearing 1/1000 th of second = 1 millisecond ½ of a second = 500 milliseconds AutoPopDelay Milliseconds that ToopTip remains onscreeen

Chapter 537 KeyPress Event