© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Variations of the Turing Machine
3rd Annual Plex/2E Worldwide Users Conference 13A Batch Processing in 2E Jeffrey A. Welsh, STAR BASE Consulting, Inc. September 20, 2007.
AP STUDY SESSION 2.
1
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 4 Computing Platforms.
Processes and Operating Systems
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
David Burdett May 11, 2004 Package Binding for WS CDL.
Microsoft Access 2007 Advanced Level. © Cheltenham Courseware Pty. Ltd. Slide No 2 Forms Customisation.
Prepared by: Workforce Enterprise Services For: The Illinois Department of Commerce and Economic Opportunity Bureau of Workforce Development ENTRY OF EMPLOYER.
Local Customization Chapter 2. Local Customization 2-2 Objectives Customization Considerations Types of Data Elements Location for Locally Defined Data.
Process a Customer Chapter 2. Process a Customer 2-2 Objectives Understand what defines a Customer Learn how to check for an existing Customer Learn how.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
Custom Services and Training Provider Details Chapter 4.
CALENDAR.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt BlendsDigraphsShort.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Windows XP Project An Introduction to Microsoft Windows XP and Office 2003.
1.
Break Time Remaining 10:00.
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
1 IMDS Tutorial Integrated Microarray Database System.
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Bits, Characters, Strings, and Structures Outline 16.1Introduction 16.2Structure Definitions.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
INTRODUCTION Lesson 1 – Microsoft Word Word Basics
Operating Systems Operating Systems - Winter 2010 Chapter 3 – Input/Output Vrije Universiteit Amsterdam.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
Benchmark Series Microsoft Excel 2013 Level 2
Sample Service Screenshots Enterprise Cloud Service 11.3.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
 Copyright I/O International, 2013 Visit us at: A Feature Within from Item Class User Friendly Maintenance  Copyright.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Adding Up In Chunks.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
: 3 00.
5 minutes.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Types of selection structures
Speak Up for Safety Dr. Susan Strauss Harassment & Bullying Consultant November 9, 2012.
1 Titre de la diapositive SDMO Industries – Training Département MICS KERYS 09- MICS KERYS – WEBSITE.
Essential Cell Biology
FIGURE 12-1 Op-amp symbols and packages.
Converting a Fraction to %
Clock will move after 1 minute
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Select a time to count down from the clock above
Import Tracking and Landed Cost Processing An Enhancement For AS/400 DMAS from  Copyright I/O International, 2001, 2005, 2008, 2012 Skip Intro Version.
Copyright Tim Morris/St Stephen's School
1.step PMIT start + initial project data input Concept Concept.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
FIGURE 3-1 Basic parts of a computer. Dale R. Patrick Electricity and Electronics: A Survey, 5e Copyright ©2002 by Pearson Education, Inc. Upper Saddle.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Ticket Information Application Introducing Sequential-Access Files.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Presentation transcript:

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application 24.2 Data Hierarchy 24.3 Files and Streams 24.4 Writing to a File: Creating the Write Event Application 24.5 Building the Ticket Information Application 24.6 Wrap-Up Tutorial 24 – Ticket Information Application Introducing Sequential-Access Files

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Create, read from, write to and update files. –Understand a computers data hierarchy. –Become familiar with sequential-access file processing. –Use StreamReader and StreamWriter classes to read from, and write to, sequential-access files. –Add and configure a MonthCalendar control.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test Driving the Ticket Information Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test Driving the Ticket Information Application Figure 24.1 Ticket Information applications GUI. Arrow buttons allow user to scroll through months MonthCalendar control ComboBox lists any events TextBox displays event details

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test Driving the Ticket Information Application 18th day of the month selected No events displayed 19th day of the month selected Event information displayed Figure 24.2 Ticket Information application displaying event information.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Data Hierarchy Data –Data has many forms, such as letters –Letters, numbers, and some special symbols are characters –The set of all characters that represent data is known as the character set –Data is broken down by a computer into bits, or binary digits –Binary digits can either be 1 or 0 –Visual Basic.NET uses Unicode characters, which means every character is 2 bytes (16 bits) –Fields are composed of characters –Records are groups of related fields –Files are groups of related records

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Data Hierarchy Data (continued) –Record keys distinguish a given record from all other records –Records are often stored in order of their record keys in a file known as a sequential file –Related files are often stored in databases –Databases are managed by programs in a database management system (DBMS)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Data Hierarchy Figure 24.3 Data hierarchy.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Files and Streams n-1... end-of-file marker Figure 24.4 Visual Basic.NETs conceptual view of an n-byte file.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Adding a dialog to open or create a file –Select OpenFileDialog in the Windows Forms tab of the Toolbox –The property FileName is the file the application reads information from –If CheckFileExists is False, the user is allowed to specify a file name –A new file is created and opened if a user specifies a file name that does not exist

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application OpenFileDialog control Figure 24.5 OpenFileDialog added and renamed.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Determining if a file name is valid –Method CheckValidity receives a file name and returns True if it is valid –Method EndsWith receives a filename and returns True if it ends with a.txt extension –If the file name is valid, the Enter and Close File Button s will be enabled

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application CheckValidity Function procedure header Figure 24.6 Method CheckValidity header.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Displaying error message if incorrect file type is provided Figure 24.7 Displaying an error message indicating an invalid file name.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure 24.8 Changing the GUIs appearance if a valid file name is entered. Enabling and disabling Button s

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application StreamWriter –Used to create objects for writing text to a file –DialogResult determines if Cancel Button was clicked and the method should therefore exit. –StreamWriter takes two arguments Name of the file to write to A Boolean value to determine if StreamWriter will append information on the end of the file

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure 24.9 System.IO namespace imported into FrmWriteEvent class. Importing namespace System.IO

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Declaring a StreamWriter object. Declaring StreamWriter

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Write Event application Form in design view. Open File… Button

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Displaying the Open dialog and retrieving the result. Displaying Open dialog If the user clicks Cancel the event handler exits Setting variable to user- specified file name

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Validating the file name and initializing a StreamWriter object. Check for valid file name Create StreamWriter object

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Clearing user input. Clearing user input

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure StreamWriter writing to a file. Writing information to file

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Closing the StreamWriter. Closing StreamWriter object

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Write Event application executing.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Open dialog displaying contents of the template Ticket Information applications bin folder.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Writing to a File: Creating the Write Event Application Figure Sequential-access file generated by Write Event application. Day and time of event, ticket price, event name and description

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 28 WriteEvent.vb (1 of 4) Importing a namespace System.IO StreamWriter that will write text to a file

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 29 WriteEvent.vb (2 of 4) Retrieve user input from Open dialog Storing filename entered by user

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30 WriteEvent.vb (3 of 4) Create StreamWriter object to associate a stream with the user-specified text file

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 31 WriteEvent.vb (4 of 4) Append data to end of file Closing the files associated stream

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure MonthCalendar template applications Form.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure System.IO namespace imported to FrmEvents.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Building the Ticket Information application –Array m_strData stores the event information read from the file –m_intNumberOfEvents stores the number of events for a given day

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure Instance variables declared in the Ticket Information application. Creating an array of String s

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure Load event handler calling method CreateEventList. You will add code to CreateEventList later

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure MonthCalendar s DateChanged event handler. Calling the CreateEventList method

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application CreateEventList –ExtractData is passed the selected date to do two actions Store event information in array m_strData assign the number of events scheduled for the specified date to m_intNumberOfEvents –Informs user whether there are events scheduled for a given day

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure CreateEventList modified to call method ExtractData and clear the ComboBox. You will add code to ExtractData in the next box

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure Displaying the events scheduled for the specified day. Extracting event name from array and displaying it in the ComboBox Indicating that events are scheduled for the day Indicating that no events are scheduled for the day

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application ExtractData used to read from a sequential file –A Do While…Loop is used to ensure that there are still characters on the file –For every entry in the file, the date is read by StreamReader and then converted to the Integer intFileDay –If the date read from the file is the same as the specified date, then the rest of the event information will be read

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure ExtractData methods variable declarations.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure Using StreamReader to read data from a sequential-access file. Creating a StreamReader object to read the calendar.txt file

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure Extracting the day from an event entry in the file. Verify that end of file has not been reached and less than 10 events are stored in the array

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure Sequentially reading event entries from the file. Store event information in a row of the array

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Building the Ticket Information Application Figure cboEvent_SelectedIndexChanged defined to display event information. Displaying event information in the TextBox.

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 50 TicketInformation-.vb (1 of 6) Importing namespace System.IO

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 51 TicketInformation-.vb (2 of 6)

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 52 TicketInformation-.vb (3 of 6) Creating StreamReader object Using method ReadLine to read the first line of the file Ensuring that the end of the file has not been reached

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 53 TicketInformation-.vb (4 of 6) Reading information from a file and storing the data in an array Using method ReadLine to skip to the next event in the file Using method ReadLine to read the day of the next event

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 54 TicketInformation-.vb (5 of 6)

Outline © Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 55 TicketInformation-.vb (6 of 6)