Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.

Slides:



Advertisements
Similar presentations
1.
Advertisements

Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type.
Objectives In this chapter, you will:
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.
VBA Modules, Functions, Variables, and Constants
Chapter 9: Sequential Access Files and Printing
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
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.
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
Chapter 7: Sub and Function Procedures
C++ for Engineers and Scientists Third Edition
Chapter 8 Arrays and Strings
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Using Arrays and File Handling
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
A First Book of ANSI C Fourth Edition Chapter 10 Data Files.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 8 Arrays and Strings
Chapter 10 Applications of Arrays and Strings. Chapter Objectives Learn how to implement the sequential search algorithm Explore how to sort an array.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Chapter 8: Manipulating Strings
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
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.
1.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
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.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Pascal Programming Today Chapter 11 1 Chapter 11.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Chapter 9: Data types and data structures OCR Computing for A Level © Hodder Education 2009.
Chapter 14: Sequential Access Files
Microsoft Visual Basic 2008: Reloaded Third Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
Variables and Arithmetic Operations
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
CIS16 Application Development and Programming using Visual Basic.net
Tutorial 9 Sequential Access Files and Printing
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS16 Application Development and Programming using Visual Basic.net
Topics Introduction to File Input and Output
Topics Introduction to File Input and Output
Presentation transcript:

Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files

Microsoft Visual Basic 2005: Reloaded, Second Edition2 Objectives After studying this chapter, you should be able to: Create a structure Declare and manipulate a structure variable Create an array of structure variables Write information to a sequential access file Align the text written to a sequential access file

Microsoft Visual Basic 2005: Reloaded, Second Edition3 Objectives (continued) Read information from a sequential access file Determine whether a file exists Code the FormClosing event Prevent a form from closing

Microsoft Visual Basic 2005: Reloaded, Second Edition4 Structures Structure statement: creates your own data type User-defined data type (or structure): data types created by using the Structure statement Member variables: variables defined within a structure Structure can include member variables of: –Any of the standard data types –Other structure types

Microsoft Visual Basic 2005: Reloaded, Second Edition5 Structures (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition6 Using a Structure to Declare a Variable Structure variables: variables declared using a structure Refer to an entire structure in code using its name Refer to a member variable using the structure name with the dot operator and the member variable name Member variables can be used like any other variables Structures are used to group related items into one unit

Microsoft Visual Basic 2005: Reloaded, Second Edition7 Using a Structure to Declare a Variable (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition8 Using a Structure to Declare a Variable (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition9 Passing a Structure Variable to a Procedure

Microsoft Visual Basic 2005: Reloaded, Second Edition10 Passing a Structure Variable to a Procedure (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition11 Passing a Structure Variable to a Procedure (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition12 Passing a Structure Variable to a Procedure (continued) Sample application using a structure: –Less code to pass a structure variable to a procedure –Stores all of the data in a single unit

Microsoft Visual Basic 2005: Reloaded, Second Edition13 Passing a Structure Variable to a Procedure (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition14 Passing a Structure Variable to a Procedure (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition15 Creating an Array of Structure Variables Use a one-dimensional array of structure variables instead of two-dimensional or parallel one- dimensional arrays Refer to a member variable in an array element by: arrayname(subscript).memberVariableName

Microsoft Visual Basic 2005: Reloaded, Second Edition16 Creating an Array of Structure Variables (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition17 Creating an Array of Structure Variables (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition18 Creating an Array of Structure Variables (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition19 Creating an Array of Structure Variables (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition20 Creating an Array of Structure Variables (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition21 File Types Reading a file: getting information from a file Writing to a file: sending information to a file Output files: files to which information is written Input files: files that are read by the computer Three types of files in Visual Basic: –Sequential –Random –Binary

Microsoft Visual Basic 2005: Reloaded, Second Edition22 File Types (continued) Sequential file: data is accessed sequentially, in consecutive order from the beginning to the end Random file: data can be accessed in consecutive or random order Binary file: data is accessed by its byte location in the file

Microsoft Visual Basic 2005: Reloaded, Second Edition23 Sequential Access Files Sequential access file: often called a text file because it is composed of lines of text Data must be read sequentially from beginning to end

Microsoft Visual Basic 2005: Reloaded, Second Edition24 Sequential Access Files (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition25 Writing Information to a Sequential Access File WriteAllText method: –Writes information to a sequential access file –File argument: contains the name of the file to be used –Text argument: contains the data to be written –Append argument: if True, data is added to end of existing file; otherwise all existing data is erased

Microsoft Visual Basic 2005: Reloaded, Second Edition26 Writing Information to a Sequential Access File (continued) My feature: exposes a set of commonly used objects to the programmer My.Computer object: allows access to objects and methods to manipulate files Computer uses a file pointer to trace where the next character will be read from or written to a file Strings.Space method: writes a specific number of spaces to a file

Microsoft Visual Basic 2005: Reloaded, Second Edition27 Writing Information to a Sequential Access File (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition28 Aligning Columns of Information in a Sequential Access File PadLeft, PadRight methods: –Pads a string with a specified number of characters based on current length of the string being padded –Aligns columns of information written to a sequential access file Aligns columns of numeric information by the decimal point

Microsoft Visual Basic 2005: Reloaded, Second Edition29 Aligning Columns of Information in a Sequential Access File (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition30 Aligning Columns of Information in a Sequential Access File (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition31 Reading Information from a Sequential Access File ReadAllText method: reads information stored in a sequential access file –File argument: contains the name of the sequential access file

Microsoft Visual Basic 2005: Reloaded, Second Edition32 Reading Information from a Sequential Access File (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition33 Determining Whether a File Exists An attempt to read a file that does not exist will cause an error FileExists method: determines if the file exists before attempting to read it –File argument: contains the name of the file

Microsoft Visual Basic 2005: Reloaded, Second Edition34 Determining Whether a File Exists (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition35 The FormClosing Event FormClosing event: –Occurs when a form is about to be closed by the program code or by the user –Allows you to trap the closing action and take any necessary actions such as saving data –Can be used to cancel the close action –Set e.Cancel = True to cancel the closing action

Microsoft Visual Basic 2005: Reloaded, Second Edition36 The FormClosing Event (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition37 The Friends Application

Microsoft Visual Basic 2005: Reloaded, Second Edition38 The Friends Application (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition39 The Friends Application (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition40 The Friends Application (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition41 The Friends Application (continued)

Microsoft Visual Basic 2005: Reloaded, Second Edition42 Programming Tutorial

Microsoft Visual Basic 2005: Reloaded, Second Edition43 Programming Example

Microsoft Visual Basic 2005: Reloaded, Second Edition44 Summary Structure statement: defines a user-defined data type or structure Structure variable contains one or more member variables Structure variable can be passed to procedures Create a one-dimensional array of structure variables –Use the dot member access operator to access the structure member variables

Microsoft Visual Basic 2005: Reloaded, Second Edition45 Summary (continued) Application can read from and write to a file Sequential access files are always accessed in consecutive (sequential) order from beginning to end ReadAllText method: reads text from a sequential access file WriteAllText method: writes text to a sequential access file Use Strings.Space, PadLeft, and PadRight methods to align data in a sequential access file

Microsoft Visual Basic 2005: Reloaded, Second Edition46 Summary (continued) FileExists method: determines if a file exists before trying to read from it FormClosing event: occurs when the form is about to be closed Use the FormClosing event to save data or to prevent a form from being closed