Chapter 7 P 1 Lists and Loops List boxes and combo boxes List box - list of items - useful for a list which does not change Combo box - list of items -

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Advertisements

CMPS 1371 Introduction to Computing for Engineers
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
1 Loops. 2 Often we want to execute a block of code multiple times. Something is always different each time through the block. Typically a variable is.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Using String Functions Left(str, nchars) - extract left nchars Right(str, nchars) - extract right nchars Mid(str,start,[nchars]) - get middle chars.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Text Box controls are used when users are required to type some input (during program execution), or output is displayed on the form (known as the user-
Lab4 ListBox Control Properties, Methods and Events.
VB Default Controls List Box, Combo Box
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Chapter 6 - Visual Basic Schneider
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Lec4 P 1 CP2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 4 Back To Index v Iteration - Looping v Arrays.
Chapter 1 P. 1 Writing Windows applications with Visual Basic Figure 1.1 The first program works as follows: (These operations can be performed in any.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Chapter 7 Lists, Loops, and Printing Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
6.3 List Boxes and Loops Some Properties, Methods, and Events of List Boxes List Boxes Populated with Strings List Boxes Populated with Numbers Searching.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
The Repetition Process in Visual Basic. The Repetition Process The capability to repeat one or more statements as many times as necessary is what really.
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
© 1999, by Que Education and Training, Appendix A, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial 6 The Repetition Structure
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
30/10/ Iteration Loops Do While (condition is true) … Loop.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab9 Control Array Print Method Printing VB Output.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
JavaScript, Fourth Edition
Select (drop-down list) Inputs. Insert/Form/List Menu.
Chapter 7 - Lists, loops and printing w List boxes and combo boxes several types can add items at design time or during run time user select from predefined.
ENG College of Engineering Engineering Education Innovation Center 1 Basic For Loops in MATLAB Programming in MATLAB / Chapter 6 Topics Covered:
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Chapter 8 P 1 Arrays and Grids Single-dimension arrays Definition An array is a sequence of elements all referred to with a common name. Other terms: table,
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
Controlling Program Flow with Looping Structures
Unit 6 Repetition Processing Instructor: Brent Presley.
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()
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 6 Controlling Program Flow with Looping Structures.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Microsoft Visual Basic 2008: Reloaded Third Edition
Introduction To Repetition The for loop
Repetition Structures Chapter 9
Lecture 7: Repeating a Known Number of Times
3rd prep. – 2nd Term MOE Book Questions.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Chapter (3) - Looping Questions.
Prepared By: Deborah Becker
Presentation transcript:

Chapter 7 P 1 Lists and Loops List boxes and combo boxes List box - list of items - useful for a list which does not change Combo box - list of items - different styles - dropdown - simple combo - dropdown style - useful for a list which the user is allowed to modify There is no Caption for most of these. The Name appears at design- time, but not at run-time.

Chapter 7 P 2 Filling the list at design time Fig. 7.3, in the Properties window, select List - enter items and - hit to exit Filling the list at run time - use the AddItem method Example lstDrinks.AddItem“Tea” cboFood.AddItemtxtMessage.Text Example P. 203 The Listindex property - each item in a list has an index; indexes start at 0 - when an item is highlighted, then Listindex is set to that value

Chapter 7 P 3 Example Consider the list Drinks List Index Coffee0 Tea1 Milk2 When the user highlights “Tea”, the Listindex is set to 1. To deselect all items, set Listindex to -1. Example lstDrinks.ListIndex = -1 Example P. 203 The Listcount property Listcount is the number of elements in a list Example lblMessage.Caption = lstDrinks.ListCount will print “3” on the form.

Chapter 7 P 4 Note: ListCount equals (highest index in the list) + 1 The List Property Display an element of a list Example To put “Milk” on the form lstDrinks.ListIndex = 2 lblMessage.Caption = lstDrinks.List (lstDrinks.ListIndex) Change an element of a list Example To replace “Tea” with ‘Coke” lstDrinks.List(1) = “Coke” Example P. 204

Chapter 7 P 5 1. Create a form with a list box and with each of the three different styles of combo boxes. 2. Enter a list for each box. 3. Write command buttons to do the following to one of the lists: - add an item - display an item - change an item

Chapter 7 P 6 For/Next Loops Definition A loop is a set of instructions which is executed more than once. Example P. 204Dim iLoopIndex As Integer For iLoopIndex = 1 to lstSchools.ListCount do something Next iLoopIndex Suppose that ListCount is 3. condition iLoopIndex is 1actions do something increment iLoopIndex condition iLoopIndex is 2 actions do something increment iLoopIndex condition iLoopIndex is 3 actions do something increment iLoopIndex condition iLoopIndex is 3actions go to the first isntruction after the loop

Chapter 7 P 7 Initialize iLoopCounter iLoopCounter < = ListCount do something True False Exit the loop (execute the first instruction after the Next statement) increment iLoopCounter Example Note that the example in the book has a Null False branch. The flowchart should be drawn as shown here.

Chapter 7 P 8 Dim iLoopIndex As Integer For iLoopIndex = 1 to lstSchools.ListCount do something Next iLoopIndex Definition The variable iLoopIndex is called the loop control variable, or counter. The number 1 is the lower bound or initial value of the loop control variable. The variable lstSchool.Count holds the upper bound or terminal value of the loop control variable. Important Do NOT attempt to change the value of the counter or the bounds within the loop. You may print them only.

Chapter 7 P 9 Altering the values of the loop control variable NO!!!

Chapter 7 P 10 Exiting For/Next loops NO!!!

Chapter 7 P 11 Negative increment on counting loops Example For iCount = 10 to 1 Step -1 Next iCount Infinite loops It is possible that you write a loop which does not terminate. Example For iCount = 10 to 1 Next iCount In this case, stop the execution of the program, start the program again, and Step through the code. Note: If your program runs but nothing happens, it may be in an infinite loop.

Chapter 7 P 12 Modify the last lab assignment. Write a loop to print out all the elements of one of your lists. Put each element into a separate label. Use a loop control array for the labels. Sending information to the printer (for creating reports) The command is Printer.Print Formatting lines - commas advance output one “print area” - semicolons separate items without as much space - trailing commas and semicolons print on the same line - print a blank line Printer.Print “ “ - the Tab function - specify the position where you want output - TAB (position)

Chapter 7 P 13 - the Spc function - skip a number of spaces - Spc (value) Selecting the font ExamplePrinter.Font.Name = “Times” Printer.Font.Size = 24 Terminating the page Printer.NewPage Terminating the job Printer.EndDoc