CSM18 FilesDr Terry Hinton1 VB - Persistence in software Information entered into a program is volatile Can switch computer off Power can be removed accidentally.

Slides:



Advertisements
Similar presentations
CSM18 Visual Basic Section 2 Department of Computing UniS 1 CSM18 Further Constructs in VB A statement is the fundamental syntactical element of a program.
Advertisements

Tutorial 12: Enhancing Excel with Visual Basic for Applications
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.
Visual Basic: An Object Oriented Approach 9 - Persistence.
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.
Software and Software Vulnerabilities. Synopsis Array overflows Stack overflows String problems Pointer clobbering. Dynamic memory management Integer.
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CIS 260 Computer Programming I in C Prof. Timothy Arndt.
Systems Software Operating Systems.
The Operating System. Operating Systems (F) What you need to know about –operating system as a program; –directory/folder.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
TERMS TO KNOW. Programming Language A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks. Each language has.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Bits and Bytes in a computers memory Inside the computer are millions of electronic switches. These are grouped together in bundles of 8. A switch can.
Systems Software & Operating systems
Topics Introduction Hardware and Software How Computers Store Data
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Standard Grade Computing System Software & Operating Systems.
Chapter 4: The Selection Process in Visual Basic.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
These days, usually used synonymously with Random Access Memory or Read- Only Memory, but in the general sense it can be any device that can hold data.
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.
Data Structure & File Systems Hun Myoung Park, Ph.D., Public Management and Policy Analysis Program Graduate School of International Relations International.
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.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
I Power Higher Computing Software Development Development Languages and Environments.
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
Chapter 14: Files and Streams. 2Microsoft Visual C# 2012, Fifth Edition Files and the File and Directory Classes Temporary storage – Usually called computer.
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.
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
Files Tutor: You will need ….
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
1 Exceptions Exception handling – Exception Indication of problem during execution – E.g., divide by zero – Chained exceptions Uses of exception handling.
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.
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.
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.
CODING VOCABULARY.  Binary  A number system based on 2  Hexadecimal  A number system based on 16  Domain  An internet location registered with the.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the differences between text and binary files ❏ To write programs.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Files and Streams Lec Introduction  Files are used for long-term retention of large amounts of data, even after the program that created the.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
( ) 1 Chapter # 8 How Data is stored DATABASE.
1 Displaying Dialog Boxes Kashef Mughal. 2 Midterm Stats Here we go  Average was  Low was 116  High was 184  Mid Quarter Grade - check any.
The purpose of a CPU is to process data Custom written software is created for a user to meet exact purpose Off the shelf software is developed by a software.
Chapter 1: Introduction to Computers and Programming
Visual Basic Fundamental Concepts
Microsoft Visual Basic 2005: Reloaded Second Edition
Topics Introduction Hardware and Software How Computers Store Data
Files.
Chapter 1: Introduction to Computers and Programming
Visual Basic..
Topics Introduction to File Input and Output
MSIS 670: Object-Oriented Software Engineering
Topics Introduction Hardware and Software How Computers Store Data
Files Handling In today’s lesson we will look at:
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Topics Introduction to File Input and Output
Arrays & Loops.
Arrays & Loops.
Presentation transcript:

CSM18 FilesDr Terry Hinton1 VB - Persistence in software Information entered into a program is volatile Can switch computer off Power can be removed accidentally Power-cuts can occur Computer System can crash We need to make data persist beyond the execution of a program

CSM18 FilesDr Terry Hinton2 Files  Files  In administration, a file is used to keep documents together in an orderly way  In a computer, a file is storage of information usually on magnetic media - discs, tapes  A computer file stores data in an order way  items are written to the file in strict sequence  items are read from the file in the same sequence

CSM18 FilesDr Terry Hinton3 Computer file mechanisms  In a computer, there must be facilities to:  Open a file, read items from a file, write items to a file and close files  to maintain a link between a program and an open file, the system assigns a file reference or handle; a variable by which the file can be identified  programming languages provide commands to access files - open, read, write,close

CSM18 FilesDr Terry Hinton4 Creating a file  To create a computer file  Ask the O/S for a file handle  Open the file for write access  Send data item variables to the file in some order  Close the file  The order of the file is defined at the point of creation  Care required to prevent file errors due to upset sequence

CSM18 FilesDr Terry Hinton5 Code to create a file Sub CreateFile( ) Dim File As Integer ‘ File handle Dim Name As String Dim Number As Integer File = FreeFile Open “MyFile.dat” For Output As #File Name = InputBox(“Name?”) Write #File, Name Number = InputBox(“Number?”) Write #File, Number Close #File End Sub Sub CreateFile( ) Dim File As Integer ‘ File handle Dim Name As String Dim Number As Integer File = FreeFile Open “MyFile.dat” For Output As #File Name = InputBox(“Name?”) Write #File, Name Number = InputBox(“Number?”) Write #File, Number Close #File End Sub Ask for handle Open File Send data Close file

CSM18 FilesDr Terry Hinton6 Retrieving data from a file  To retrieve data from a file  Ask the O/S for a file handle  Open the file for read access  Read data items from the file - they will be in the same order as when written  Close the file  File problems generally due to sequence errors  e.g. program reads a string when expecting a number

CSM18 FilesDr Terry Hinton7 Code to retrieve data from a file Sub ReadFile( ) Dim File As Integer ‘ File handle Dim Name As String Dim Number As Integer File = FreeFile Open “MyFile.dat” For Input As #File Input #File, Name MsgBox Name Input #File, Number MsgBox Number Close #File End Sub Sub ReadFile( ) Dim File As Integer ‘ File handle Dim Name As String Dim Number As Integer File = FreeFile Open “MyFile.dat” For Input As #File Input #File, Name MsgBox Name Input #File, Number MsgBox Number Close #File End Sub Ask for handle Open File Read data Close file

CSM18 FilesDr Terry Hinton8 Types of file  Files can be organised in a number of ways  Tabular  Character based text  Text with line-breaks  Sequential - write or read whole file  Random access - access an item using index  File organisation is determined by...  the program code that writes the file  the variable types stored

CSM18 FilesDr Terry Hinton9 File formats “Fred Bloggs”, “1 High Street”, £200 “Jane Smith”, “55 Glen Road”, £28.55 The key feature of this file is that it is composed of a continu ous sequence of text characters with no format beyond the la nguage used. Strictly, it should be seen as one long line of te xt characters. This type of file is distinguished by the use of line breaks (special, non-printing characters) to preserve the format of the text. Each line ends with a line-break and so need not be a fixed length. Tabular Text with Line breaks Character

CSM18 FilesDr Terry Hinton10 Files and objects We send objects to a file by serialising them The data in each object is written out as a sequence of values, either in binary or character form The class is responsible for sending and retrieving object data Call a serialised file of objects to be a stream Use streams to transmit and receive objects over a number of different media

CSM18 FilesDr Terry Hinton11 Streams Provide an object with Save and Load methods By keeping the code within the class, objects manage their own streams Complex hierarchical objects can manage themselves hierarchically

CSM18 FilesDr Terry Hinton12 Objects and Databases Streams of objects have an inherent problem Need to send and retrieve the whole hierarchy No chance of reading one or two items back OK for a few hundred or thousand items Not possible for millions In this case, a database provides the solution Structured random access Fast retrieval of objects and sets of objects

CSM18 FilesDr Terry Hinton13 From Array to File Dim Data (1..100) As Single For I= 1 to 100 Data(I) = … Next I For I= 1 to 100 Write #File, Data(I) Next I

CSM18 FilesDr Terry Hinton14 Visual Basic End