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
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Advertisements

Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Trapping Errors and Debugging Code. Programming errors can vary by … Type Cause Effect Severity Other factors Error types Include Syntax Logic Compile.
Files Organisation sequential files. Readings u Schneider Chapter 8 u Shelly Cashman to 9.14; to 9.11 u Meyer to 2-37; 1995.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Component 9, Slide 1 CP2030 Copyright © University of Wolverhampton CP2030 Visual Basic for C++ Programmers v Component 9 working with text files and random.
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.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Reading and Writing Files Keeping Data. Why do we use files? ä For permanently storing data. ä For dealing with information too large to fit in memory.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Component 10a, Slide 1 CP2030 Copyright © University of Wolverhampton CP2030 Visual Basic for C++ Programmers v Component 10 – Working with Binary Files.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Saving and Loading Simple Text Files A sequential file stores characters one after the other like songs on a cassette tape. New characters are added to.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Don Kussee _appendix1 Simple Text Editor Don Kussee.
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
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 TWO Creating Simple Visual Basic.NET Windows Applications.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 11 Accessing Database.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Indexed and Relative File Processing
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
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.
Visual Basic.NET BASICS Lesson 5 Exponentiation, Order of Operations, and Error Handling.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 7 Files.
5 1 Data Files CGI/Perl Programming By Diane Zak.
1.
© 1999, by Que Education and Training, Chapter 9, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
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!
READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential.
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.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events Visual Basic. NET.
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,
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
The SPIM Trap Handler Syscall Trap handler services String operations File operations Memory allocation Central Connecticut State University, MIPS Tutorial.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
VSAM ESDS and RRDS Department of Computer Science Northern Illinois University September 2005 Some of the illustrations are from VSAM: Access Method Services.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Sequential Processing to Update a File Please use speaker notes for additional information!
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Department Array in Visual Basic
Module IV Memory Organization.
Visual Basic 6 Programming.
CIS16 Application Development and Programming using Visual Basic.net
Microsoft Visual Basic 2005 BASICS
Chapter 8 - Visual Basic Schneider
Topics Introduction to File Input and Output
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 10: Data Files  Create data files –Reading, writing, opening, closing  Differentiate sequential & random files  Trap user errors and handle them  Fixed length strings in user data types  Read/Write random data files  Updating a random file  Using the InputBox function

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Data Files  Data files consist of records & fields  Record key determines a record’s position in a file  Two common file organizations are sequential and random  Process a file by 1. opening the file 2. processing the data, 3. closing the file

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill FreeFile and Close Statements  FreeFile function returns the next unused file number –intFileNumber = FreeFile –In large projects, file numbers are hard to track and allocate  Close issued automatically when you end  Issue Close statement before leaving prog. –Close #1 or Close #1, #2

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Sequential File Organization  Sequential file records are stored one after another  Use Write to output data  Use Input to read data  File must be opened prior to first use  Form: Write #fn, item 1, item 2,…, item n Input #fn, item 1, item 2,…, item n  EOF function signals end of file

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Writing to a Sequential File  Write statement places data in output  Form: Write #file, o 1, o 2, …, o n  You can separate fields with commas or semicolons  Output fields are separated with commas, and strings are quoted.  / ends each record  Write #1, txtLname.Text, 54.89

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Reading Data in a Sequential File  Form: Input #fn, item 1,…,item n  Separate fields items with commas  File number must be that of an open file  When you read the last record, end-of-file signals  You detect end of file with the EOF function: EOF(FileNumber)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Trapping Program Errors  Errors may be trapped asynchronously  Visual Basic generates an error number whenever an error occurs  To handle errors, you must –Turn on error handling feature: On Error... –Create error handling code –Determine what is to be done after processing the error (continue, end program,…)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill The Err Object  The Err object holds information about error that just occurred  Err.Source holds the source of the error  Err.Number holds the error number  Err.Description contains error description  You can raise an error condition—turn on an error—with: Err.Raise Number:=xx

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Coding Error-Handling Routines  On Error statement designates error handler  Code to handle errors follows line label  Line label appears on line by itself and ends with a colon  A Case statement works well to sort out errors with a "switchboard"  Continue execution with Resume statement

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Exit and Exit Sub Statements  Exit Sub immediately exits current sub procedure  Exit Function immediately exits current function  Exit is used to prematurely halt execution of sub procedure or function when extraordinary conditions occur  Place Exit Sub above error handling label

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Saving Changes to a File  When data changes, ask users if they want to save the changes before program ends  Changed data is known as “dirty” data  Keep track of data changes with a global boolean flag  Any procedure that allows data to change should set the flag to True—indicating “dirty” data file  Check file just before ending program

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Sequential File Prog. Example  You can load a combo box by reading from a data file and executing the AddItem method  Reading file & list filling halts when EOF occurs on input file  (See Hands On Programming example)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Random data files  You can read/write data in any order  Open “filename” For Random As #1 LEN=x  Get #filenumber, [record#], RecordName  RecordName is a user-defined data type: Type FullName strLastName As String * 20 strFirstName As String * 15 End Type

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Random data files  Output: Put Put #filenumber, [recordnumber], Recordname  Put #1, iRecordNo, pCustomerRecord  Get & Put statements read an entire record  You refer to fields in user-defined structure by recordname.fieldname  lstName.AddItem mRec.LastName  end of file is calculated via record lengths