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.

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
Files Organisation sequential files. Readings u Schneider Chapter 8 u Shelly Cashman to 9.14; to 9.11 u Meyer to 2-37; 1995.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
Chapter 11 Data Files Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
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.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
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.
Chapter 9: Sequential Access Files and Printing
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
An Introduction to Programming with C++ Fifth Edition Chapter 13 Sequential Access Files.
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.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Manipulating Strings.
Chapter 9 Files I/O: Files, Records and Fields. Basics of File Input and Output Have created both input and outputs from programs. Persistent data: What.
Chapter 8 Printing 1. In COBOL you send data to the printer by writing data to a file. In COBOL, the printer is defined as a file, and it is opened, closed,
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 13 Files and Exception Handling 1.
Visual C Sharp – File I/O - 1 Variables and arrays only temporary - lost when a program terminates Files used for long term storage (Data bases considered.
File Handling. Data Files Programs that can only get data from the user interface are limited. –data must be entered each time. –only small amounts of.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Data files and databases. Need a control to browse to a file Standard controls for drive folder and list not much use The CommonDialogs control offers.
11-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Input and Output. Announcements  Exam Next Wednesday –Next Monday: Review session.  Invited talk: –7:30 PM,Tuesday, Oct 28th. –Prof. Katherine Socha.
Tutorial 9: Sequential Access Files and Printing1 Tutorial 9 Sequential Access Files and Printing.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Computer Programming TCP1224 Chapter 13 Sequential File Access.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
5 1 Data Files CGI/Perl Programming By Diane Zak.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
© 1999, by Que Education and Training, Chapter 9, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
Sequential files School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 12, Monday 4/07/2003)
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.
READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential.
Files Tutor: You will need ….
1 Objectives ❏ To understand the differences between text and binary files ❏ To write programs that read, write, and/or append binary files ❏ To be able.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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,
BACS 287 File-Based Programming. BACS 287 Data Hierarchy  Database - Collection of files, relationships, integrity information, etc  Files - All records.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Compunet Corporation1 Programming with Visual Basic.NET Input and Output Files Lecture # 6 Tariq Ibn Aziz.
Files in Python The Basics. Why use Files? Very small amounts of data – just hardcode them into the program A few pieces of data – ask the user to input.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the differences between text and binary files ❏ To write programs.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Programming II I/O Streams and Data Files 1(c) Asma AlOsaimi.
Chapter 14: Sequential Access Files
Microsoft Visual Basic 2005: Reloaded Second Edition
Topic: File Input/Output (I/O)
Fundamentals of Python: First Programs
Starting Out with Programming Logic & Design
Files and Streams.
Topics Introduction to File Input and Output
Visual Basic 6 Programming.
Using Text Files in Python
Text / Serial / Sequential Files
Random Access Files / Direct Access Files
Topics Introduction to File Input and Output
Chapter 8 - Visual Basic Schneider
Files and Streams.
Topics Introduction to File Input and Output
Text / Serial / Sequential Files
Presentation transcript:

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 permanent way to store data

File Handling Three types of file can be used for storing data Sequential Sequential Random Random Binary Binary

Sequential Files Sequential files are useful for: Storing text Easy implementation in programs Where real-time editing of file(s) is not required

Random Files Random file structures are useful for Files that require real-time editing Storing records

Binary Files Binary Files are useful for Storing numbers, programs and images Where no defined file structure is present They will not be used in this course

Sequential Files Have a universal standard format and are used in text editors such as windows notepad Numerical data is stored as a string e.g., 5.32 would be stored as “5.32” They are read from start to finish and so cannot be read and written to simultaneously

Sequential Files Data is ALWAYS written and retrieved as CHARACTERS. Hence, any number written in this mode will result in the ASCII Value of the number being stored. For Example, The Number 17 is stored as two separate characters "1" and "7". Which means that 17 is stored as [ ] and not as [ 17 ].

Sequential Files Are like a one dimensional array The text, ONE DAT might be stored as: “DTENO CR ”A EOF

Sequential Files Files are manipulated in 3 stages: File Open Process File Close File

Sequential Files File Open created and then opened If the file does not exist it is created and then opened by the operating system. memory (RAM) A portion of memory (RAM) is reserved by the Operating System.

Sequential Files Processing a File written to or read When a file is open it can be written to or read from. (both in the case of random and binary files) backing store. Writing to a file will save it to backing store.

Sequential Files Closing a file must then be closed When a file has been opened and processed it must then be closed. release the memory. The Operating system will then release the memory.

Visual Basic VB supports all three file types, but you are only likely to use two of them Text files Random Access files

Text Files

Sequential/Text Files Input File opened for read-only access. Output File opened for output which is only write-to or create Append The file is opened for adding new data to an existing file. This is the default setting. Random The file is open for random access. This is writing or reading one record at a time. Binary The file is opened in binary mode

Using the OpenFileDialog control Dim Filename as String OpenFileDialog1.ShowDialog() Filename= OpenFileDialog1.Filename lblFilename.Text = Filename

Opening Files FileOpen(1, Filename, OpenMode.Input) ‘to read from the file FileOpen(1, Filename, OpenMode.Output) ‘to write to the file FileOpen(1, Filename, OpenMode.Append) ‘to write to the end of the file Note – 1 assigns the file the number 1. All files are identified by a number, not by their name. If you have two or more files open at once they must have different numbers.

Opening Files The FileOpen statement opens a file if it exists. When you open a file to read from it, an error results if it does not exists. When you open a file to write to it, if it doesn’t exist FileOpen first creates it and opens it. Filename contains the name and path of the file

Opening (creating) a Sequential File This algorithm would achieve this: 1. Enter Filename 2. Open File for writing 3. Input Information 4. Save to file 5. Close file

Opening (creating) a Sequential File This algorithm would achieve this: Enter Filename Enter Filename Open File for writing Open File for writing Input Information Input Information Save to file Save to file Close file Close file Filename= OpenFileDialog1.FileName

Opening (creating) a Sequential File This algorithm would achieve this: Enter Filename Enter Filename Open File for writing Open File for writing Input Information Input Information Save to file Save to file Close file Close file FileOpen(1, Filename, OpenMode.Output)

Writeline(1, DataToBeWritten) Opening (creating) a Sequential File This algorithm would achieve this: Enter Filename Enter Filename Open File for writing Open File for writing Input Information Input Information Save to file Save to file Close file Close file

Opening (creating) a Sequential File This algorithm would achieve this: Enter Filename Enter Filename Open File for writing Open File for writing Input Information Input Information Save to file Save to file Close file Close file FileClose (1)

Opening a sequential file The final code would look like: Dim Filename as string ‘File manipulation Program ‘Create File Private sub cmdCreateFile_Click() OpenFileDialog1.ShowDialog() Filename = FileDialog1.FileName FileOpen(1,Filename, OpenMode.Output) WriteLine(1,DataToBeWritten) FileClose (1) End Sub