Creating Sequential Files, Adding Data, & Deleting Data.

Slides:



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

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.
CS0004: Introduction to Programming Select Case Statements and Selection Input.
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.
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 11: Data Files & File Processing In this chapter, you will learn about Files and streams Creating a sequential access file Reading data from a.
Chapter 11 Data Files Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
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
Chapter 8 - Visual Basic Schneider1 Chapter 8 Sequential Files.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
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.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Input/Output CE 311 K - Introduction to Computer Methods Daene C. McKinney.
C HAPTER 8 – F ILES 1. P RELIMINARIES Private Sub Form1_Load() Handles MyBase.Load 'read the file into an array. The file is assumed to be comma-delimited.
Tutorial 11 Using and Writing Visual Basic for Applications Code
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.
1 Chapter 8 – Text Files 8.1 Managing Text Files 8.2 StreamReaders, StreamWriters, and Structured Exception Handling 8.3 XML.
Break Processing Please use speaker notes for additional information!
1 Text Files Managing Text Files StreamReaders, StreamWriters, ReadAllLines, and WriteAllLines Method The OpenFileDialog Control Structured Exception Handling.
Chapter 8 - VB 2008 by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files 8.2 Using Sequential Files.
File I/O 11_file_processing.ppt
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.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
11-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
CSEB114: Principle of programming Chapter 11: Data Files & File Processing.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 5 Loops, File, and Random Numbers.
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.
Files Tutor: You will need ….
Pay Example (PFirst98) Please use speaker notes for additional information!
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
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.
Compunet Corporation1 Programming with Visual Basic.NET Input and Output Files Lecture # 6 Tariq Ibn Aziz.
Visual BASIC Programming For CCS 301 course Dr. Ahmad ABDELHAY.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Chapter 14: Sequential Access Files
3rd prep. – 2nd Term MOE Book Questions.
Chapter 8 – Sequential Files
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Chapter (3) - Looping Questions.
Variable Review & IO User 12/26/2018.
Chapter 3.5 Input and Output
Input and Output.
Text / Serial / Sequential Files
Tutorial 9 Sequential Access Files and Printing
CIS16 Application Development and Programming using Visual Basic.net
Topics Introduction to File Input and Output
Chapter 8 - Visual Basic Schneider
Input and Output.
Topics Introduction to File Input and Output
Chapter 11 Saving Data and Objects In Files
Text / Serial / Sequential Files
Input and Output Chapter 3.5
CHAPTER FOUR VARIABLES AND CONSTANTS
3.3 – Invoke Workflow File Exercise 3.2: Extract as Workflow
Presentation transcript:

Creating Sequential Files, Adding Data, & Deleting Data

Creating a Sequential File Filename 156 alphanumeric characters (including spaces & periods) Three character extension identifying file type Filespec Includes full path Default – no need to include full path Current project Debug/bin

Creating a Sequential File Execute statement of the form Dim sw As IO.StreamWriter = IO.File.CreateText (filespec) Where sw is a variable name. Setup a new line of data in a temporary buffer sw.WriteLine (datum) Transfer the new line of data to disk & sever communication sw.Close()

Example

Create File Button Click Event Dim sw As IO.StreamWriter =IO.File.CreateText("GreatNames.txt") sw.WriteLine("Atanasoff") sw.WriteLine("Babbage") sw.WriteLine("Codd") sw.Close() MessageBox.Show("Names Recorded", "file Status")

Results

Open GreatNames.txt

Add Items to Existing File Execute statement Dim sw As IO.StreamWriter=IO.File.AppendText(filespec) Use WriteLine method to place data into file. Close the file with the statement sw.Close()

Dim sw As IO.StreamWriter=IO.File.AppendText(filespec) Appends data to the end of file Creates file if one does not exist

Three Mutually Exclusive File Handling Modes for Sequential Files CreateText OpenText AppendText

Avoid Opening a Nonexistent File IO.File.Exists(filespec) Method Returns True or False True indicates file exists

Code to Open File with Test for Existence Dim strMessage As String Dim sr As IO.StreamReader If IO.File.Exists("GreatNames.txt") Then sr = IO.File.OpenText("GreatNames.txt") Else strMessage = "Either no file has yet been created or the file " strMessage &= "GreatNames.txt" & " is not where expected." MessageBox.Show(strMessage, "File Not Found") End If

Lab Exercise – CE6 Download & Unzip YOB.zip