Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.

Slides:



Advertisements
Similar presentations
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Advertisements

© 1999, by Que Education and Training, Chapter 6, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
File Handling Advanced Higher Programming. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a.
Lecture Roger Sutton CO331 Visual Programming 19: Simple file i/o Exceptions – Error handling 1.
Data Files In all your projects so far, the user has entered information through text-boxes This input method is unsatisfactory for large quantities of.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
3. (a) Code a procedure to accept details from a user relating to an unknown numbers of employee entries. Each time a specified number of new employees.
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.
Chapter 31 Fundamentals of Programming in VB(Continue I) Numbers Arithmetic Operations Variables Incrementing the Value of a Variable.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
Chapter 7 - Visual Basic Schneider
Chapter 8 - VB.Net by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files Creating a Sequential File Adding Items to a Sequential File Error Trapping.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Visual Basic: An Object Oriented Approach 5: Structured Programming.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Break Processing Please use speaker notes for additional information!
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 6: Sequential Data Files.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
Sequential Files Chapter 13. Master Files Set of files used to store companies data in areas like payroll, inventory Set of files used to store companies.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 8 - Visual Basic Schneider
5 1 Data Files CGI/Perl Programming By Diane Zak.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
1.
Sequential files School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 12, Monday 4/07/2003)
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
VAT Calculator program Controls Properties Code Results.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Visual Basic - Break Processing
Processing multiple files
Microsoft Visual Basic 2005: Reloaded Second Edition
Programming in visual basic .net Visual Basic Building Blocks
Chapter 6: Sequential Data Files
Chapter 7 Arrays.
Excel VBA Day 3 of 3 Tom Vorves.
Introduction to VB programming
Chapter 4 - Visual Basic Schneider
Topics Introduction to File Input and Output
Department Array in Visual Basic
Files [Computing] Computing.
Writing a Complete Program
Chapter 8 - Visual Basic Schneider
Topics Introduction to File Input and Output
Presentation transcript:

Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files

Chapter 8 - Visual Basic Schneider2 Outline and Objective Creating Sequential Files Adding items to Sequential Files Using Sequential Files –Sorting Sequential Files –Merging Sequential Files –Control Break Processing

Chapter 8 - Visual Basic Schneider3 What is a File? A collection of related data kept in secondary storage Two types of files: program files, text(data) files Data files are usually made up of a collection of records. A record is collection of fields.

Chapter 8 - Visual Basic Schneider4 Creating a Sequential File Choose a file name Choose a reference number Open the file for Output Write to the file Close the file

Chapter 8 - Visual Basic Schneider5 Example: Private Sub cmdCreateFile_Click() Dim name1 As String, name2 As String ' Demonstrate use of Write # statement Open "PIONEER.TXT" For Output As #1 Write #1, "ENIAC" Write #1, 1946 Write #1, "ENIAC", 1946 name1 = "Eckert" name2 = "Mauchly" Write #1, 14 * 139, "J.P. " & name1, name2, "John" Close #1 End Sub File name Reference number Write to the file Close the file

Chapter 8 - Visual Basic Schneider6 Adding Items to a Sequential File Choose a reference number for the file Open the file for Append Write to the end of the file Close the file

Chapter 8 - Visual Basic Schneider7 Example (Adding a player to a BASEBALL1.TXT file) Private Sub Form_Load() Open App.Path & "\BASEBALl.TXT" For Append As #1 End Sub Private Sub cmdAddRec_Click() Write #1, txtPlayer.Text, txtTimes.Text, txtHits.Text txtPlayer.Text = “ “ txtTimes.Text =“ ” txtHits.Text=“ ” txtPlayer.SetFocus End Sub Private Sub cmdQuit_Click() Close #1 End End Sub Opening the file in append mode

Chapter 8 - Visual Basic Schneider8 Sequential File Different modes in which a file can be used: –Output –Input –Append A file should not be open in two different modes at the same time.

Chapter 8 - Visual Basic Schneider9 Error Trapping Visual Basic has a device, called error-trapping, for preventing some types of errors. If an error occurs while error-trapping is active, two things happen: 1. An identifying number is assigned to the Number property of an object called Err 2. The program jumps to error-handling routine.

Chapter 8 - Visual Basic Schneider10 Setting up error-trapping in a procedure : Make the first line of the procedure: On Error GoTo ErrorHandler Type the statements to carry out the procedure End the procedure by typing Exit Sub ErrorHandler: error-handling routine Resume

Chapter 8 - Visual Basic Schneider11 Example ( error-handling routine to handle a “division by zero” error) Private Sub cmdDivide_Click() On Error GoTo ErrorHandler Dim a As Single, b As Single, c As Single picResult.Cls a = Val(InputBox("Enter the numerator.")) b = Val(InputBox("Enter the denominator.")) c = a / b picResult.Print ”The result is = “; c Exit Sub

Chapter 8 - Visual Basic Schneider12 The error-handling routine Exit Sub: ‘ Division by zero is error code 11 If Err = 11 Then picResult.Print "You tried to divide by 0, which is illegal" picResult.Print "Try again.” b=Val(InputBox(“Enter the denominator”)) End If Resume End Sub Line Label

Chapter 8 - Visual Basic Schneider13 Sorting Sequential Files The records of a sequential file can be sorted on any field by first reading the data into parallel arrays and then sorting on a specific field, and then rewriting the data into a file.

Chapter 8 - Visual Basic Schneider14 Merging Sequential Files Steps to merge two sorted files: 1. Open the two sorted files For Input and a third file For Output 2. Get the two items of data from each file 3. Compare and repeat until the EOF. If one item precedes the other, write it into the third file and get another item from the file If the two items are identical, write it into the third file and advance to the next items in both files. 4. Write the remaining items to the third file 5. Close the three files.

Chapter 8 - Visual Basic Schneider15 Control Break Processing While processing sequential files, you can introduce control variables to trigger a computation or a specific task. Each change in value of the control variable is called a break.

Chapter 8 - Visual Basic Schneider16 Common Errors Opening the file in wrong mode Not using Write statement every time you need to add data to a file Not closing the file