VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

Match-and-Stop Search Will find FIRST match Use Boolean variable to denote whether a match has been found or not Found initially False If a match is found,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 2.
Loops Counting down from N to 1 in assembly we used JUMP statements to repeat previous instructions thus looping READ LOOP: WRITE SUB decrement JPOSLOOP.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
Chapter 5: Loops and Files.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Two-Dimensional Arrays School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 11, Friday 4/04/2003)
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
C++ for Engineers and Scientists Third Edition
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 7: Working with Arrays
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
VB CSCI130 Instructor: Dr. Lynn Ziegler, Slides originally designed by Dr. Imad Rahal, updated by Lynn Ziegler LAYEROrder High-order P.L.: Visual Basic1.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
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.
VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 11 Sorting and Searching.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
1 Arrays An array is a collection of data values, all of which have the same type. The size of the array is fixed at creation. To refer to specific values.
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Input and Output. Announcements  Exam Next Wednesday –Next Monday: Review session.  Invited talk: –7:30 PM,Tuesday, Oct 28th. –Prof. Katherine Socha.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
6.2 For…Next Loops General Form of a For…Next Loop
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
22/11/ Selection If selection construct.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
Two Forms Please use speaker notes for additional information!
Pascal Programming Today Chapter 11 1 Chapter 11.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Loops and Files. 5.1 The Increment and Decrement Operators.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
VB CSCI130 Instructor: Dr. Imad Rahal LAYEROrder Application SW: Excel & Access2 High-order P.L.: Visual Basic1 Low-order P.L.: Assembly3 System Software:
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Controlling Program Flow with Looping Structures
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Language Find the latest version of this document at
Chapter Looping 5. The Increment and Decrement Operators 5.1.
情報基礎 A Lecture 9 Takeshi Tokuyama ・ Jinhee Chun Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Chapter 6 Controlling Program Flow with Looping Structures.
01/05/100 1 Loops/Iteration Used to repeat an action Must have a STOP condition Three flavors - for, while, do/while.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Processing multiple files
Chapter 7 Arrays.
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Arrays An Array is an ordered collection of variables
If selection construct
Presentation transcript:

VB PROJECT “PROJECT SAMPLES”

For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam grades for each of 30 students For Student = 1 to 30 For Grade = 1 to 3 Grade = InputBox(“Enter a grade”,,”Input”)‏ Next Grade Next Student The nested (inner) loop is executed completely for each execution of the outer loop --- how many? Outer 30, inner 3*30=90 We can nest loops but they may not overlap i.e. if the start of a loop L1 starts after that of another one, L2, then L1’s end must come before L2’s

Input & Output Opening files for Reading create project and save it first and then save the data file in the same folder Open App.Path & “\FILE NAME" For Input As #1 File must be in the project’s folder Do Until EOF(1) (or Do While Not(EOF(1)))‏ Input#1, col1, col2, col3,… Close #1 Opening files for Writing Write a new file Open App.Path & "\infile.txt" For Output As #2 Write #2, firstValue, secondValue,.... CLOSE #2 Will overwrite all that was there previously!!!! Append to a file Open App.Path & "\infile.txt" For Append As #1 Will add to end of file

Arrays We have been using variables pointing to a single memory register holding a single value What if we have to store a list of related data E.g. exam-1 scores for this class declare 30 variables? An array is a variable that holds multiple data pieces such as a list or table A block of memory registers Declare it by giving a name and a size Dim ArrayName(1 to MaxSize) As DataType Refer to stored data by their positions

Arrays Dim Runner(1 to 75) As String 75 memory registers are set up for array Runner Each holds a name string To print the 15 th runner: picResults.Print Runner(15)‏ Second array could hold the time for the runner Enter runner and time with pop ups for 10 runners Write contents to a file: “runnerTimes” Average the contents of the runner times array Dim Times(1 to 75) As Single, Pos As Integer For Pos = 1 to 75 Sum = Sum + Times(Pos)‏ Next Pos Avg = Sum/75 Display runners and times in a picture box Parallel Arrays Single marker that goes through the two arrays

Arrays and Files Runners and times program Parallel arrays 1 - Reads names & times into arrays used multiple times done in a separate step maintain CTR as an array index 2- Find average size vs. capacity Change to display all runners with less time than an average

Sequential Search Two types of array sequential searching problems (1) Match-and-stop (first match)‏ Begin at first array element Compare search value with each data element If there a match, stop and return match or its position Otherwise, go to next element and repeat Stop looking when a condition is satisfied or when we have finished the list in which case we return a failure Usually we use a Do Loop

Match-and-Stop Search Use Boolean variable to denote whether a match has been found or not Found initially False If a match is found, we set it to True Dim Found As Boolean Found = False POS = 0 SearchValue = Inputbox… Do While (Found=false and POS<(Array size))‏ POS = POS +1 If Array(POS) = SearchValue Then Found=True End If Loop If Found= True then Print success at location POS Else Print Failure End If

Match-and-Stop Search Read an array of 75 runner names and array of 75 runner times from a file and search for a specific name input through an inputbox If found, display rank and time Else, display not found What would happen if we didn’t use POS<(Array size) ? Try a successful and an unsuccessful search What would happen if the else is included in the loop and not outside

Sequential Search (2) Exhaustive search (must check all array elements)‏ E.g. find all values less than a given value, maximum, or minimum Must scan whole array We use a For Loop For Pos = 1 to (CTR)‏ If condition is true then do action

Exhaustive Search Write a program that reads numbers from a file (unknown size but say less than 100) into an array Uses the array to find and display all numbers larger than an input minimum threshold

Exhaustive Search Private Sub cmdSearchButton_Click()‏ Dim CTR As Integer, Pos As Integer, Min As Integer Dim Numbers(1 to 100) As Integer Open App.Path & "\Numbers. txt" For Input As #1 CTR = 0 Do Until EOF(1)‏ CTR = CTR + 1 Input #1, Numbers(CTR)‏ Loop Min = InputBox(“Enter your minimum threshold please”, ”INPUT”)‏ For Pos = 1 to CTR If Min < Numbers (Pos) Then picResults.Print Numbers(Pos)‏ End If Next Pos End Sub