Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.

Slides:



Advertisements
Similar presentations
Programming with Microsoft Visual Basic th Edition
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
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.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Using String Functions Left(str, nchars) - extract left nchars Right(str, nchars) - extract right nchars Mid(str,start,[nchars]) - get middle chars.
Lab4 ListBox Control Properties, Methods and Events.
VB Default Controls List Box, Combo Box
Chapter 5: Loops and Files.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab5 ListBox Control Properties, Methods and Events.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
CHAPTER SIX.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 What are the different types of loops? ◦ Do….While  Performs statements within loop while a condition is true ◦ Do….Until  Performs statements within.
Tutorial 61 List Box Control Can be used to display a set of choices from which the user can select only one You also can create multi-selection list boxes.
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Teacher’s Assessment Assistant Worksheet Builder Starting the Program
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.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
© 1999, by Que Education and Training, Appendix A, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
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.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter 7 Lists, Loops, and Printing Programming In Visual Basic.NET.
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 -
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
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.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Lists, Loops, and Printing Chapter 7.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events Visual Basic. NET.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
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()
Microsoft Visual Basic 2012 CHAPTER FIVE Decision Structures.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
© 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,
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Microsoft Visual Basic 2008: Reloaded Third Edition
Repeating Program Instructions
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Chapter 7 Lists, Loops, and Printing
Prepared By: Deborah Becker
Presentation transcript:

Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Ch 7: Lists, Loops, & Printing  List Boxes & Combo Boxes  Populating list boxes and combo boxes  Do Loops, For/Next Loops  MsgBox returned values  String Functions  Send Info. to the Printer with Print method  Formatting Output

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill List Boxes & Combo Boxes  List/Combo boxes allow a list of items  Types include –simple combo boxes –dropdown combo boxes –dropdown lists  Combo box has style property; list does not  Combo box has design-time text property; list box has only run-time text property.  Combo box does not have a MaxLength property; a list box does.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Filling the List  You can fill the list at design- or run-time  Fill at design time if list rarely changes –Click List property, type entry, press Ctrl+Enter –Make Sorted property true to keep list in order  Fill at run time if list is volatile –Use AddItem method to add items –Form: object.AddItem value [,Index] –Example: lstFruits.AddItem "Apple"

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill List/Combo Box Methods  AddItem - Add item to list cboFruits.AddItem "Kiwi" cboFruits.AddItem cboFruits.Text  Clear - Delete all items from the list cboFruits.Clear

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill List/Combo Box Properties  Sorted maintains list in order (if true)  ListIndex holds user-selected item index number (begins at zero, -1 if none selected)  ListCount is number of items in list  List object.List(index) extracts string value of list item  Setting the ListIndex property highlights a selection in the list

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill List/Combo box Events  Change Occurs when user types text into combo box (list box does not have this)  GotFocus Occurs when control receives control  LostFocus Occurs when control loses control

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Do Loops (1)  Allow repeated execution of instructions  Do loop terminates on a condition you specify  Do loop can test for condition at –Top of loop (pretest) –Bottom of loop (posttest)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Do Loops (2)  Loops can continue while a condition is either true or false –Go while True:…While condition –Go while False:…Until condition  Be sure to change the loop variable within the loop or it will loop infinitely!

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill For/Next Loops (1)  For/Next allows you to repeat series of instructions using a counter (a loop index)  Form: For loopindex = initialvalue To endvalue [Step k] …body of loop… Next [loopindex]

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill For/Next Loops (2)  You can loop “backwards” by using a negative increment  Loop testing is done before executing body  Do not change the loop control inside the body  Halt infinite loops by pressing Ctrl+Break  Exit For allows early For loop exit from within the body

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill For/Next Loops (3)  Use For/Next loop when you know the number of times a loop will run  When loop decrements, the test is for strictly less than the ending value  The For/Next ending condition may exist before entering the loop. If so, then the loop body is skipped

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Using the MsgBox Function  MsgBox has a function form (we have used statement form until now)  MsgBox function returns which key the user pressed of those available  Use VB intrinsic constants to determine which key was pressed.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill MsgBox Values ConstantValueButton Pressed vbOK 1OK vbCancel 2Cancel vbAbort 3Abort vbRetry 4Retry vbIgnore 5Ignore vbYes 6Yes vbNo 7No (ignore the Value column; use intrinsic constants)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Using String Functions  Left(str, nchars) - extract left nchars  Right(str, nchars) - extract right nchars  Mid(str,start,[nchars]) - get middle chars  str is any string, nchars is integer, and start is integer number of starting position.  Len(str) returns # chars in string

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Using String Functions (2)  String functions and looping facilitate the “zooming” feature of many Microsoft list boxes and combo boxes.  “Zooming” causes a search of the list, refining the search with each additional keystroke the user enters.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Sending Info. to the Printer  Visual Basic’s Print method applies to a Form, a printer object, the Debug window, or a picture box  Printer.Print — sends output to printer  Print is a method of the Printer object  Printing is somewhat difficult, because VB is designed to use with forms, not printers

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Formatting Lines  Printer.print x, y, z prints in three "zones"  Printer.print x;y;z ignores zones  Trailing comma or semicolon causes next print method to continue the line  Each.print starts on a new line  Printer.print (alone) prints blank line

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Formatting Lines  Tab(20) advances to 20th position: Printer.Print Tab(20); "Name:"  Spc(17) inserts spaces (17) in line  Numbers print with one space for sign of #  Printer.NewPage sends page to printer & goes to new page  Printer.EndDoc sends page to printer & halts print job

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Printing to Picture Box  You can use Print method with a picture box to avoid actually printing a result:  picMyPictureBox.Print "howdy" prints to a picture box

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Hands-On Programming Example