1 / 26

Tutorial 10 Random Access Files

Tutorial 10 Random Access Files. Random Access Files Lesson A Objectives. After completing this lesson, you will be able to: Define the terminology used with random access files Create a record structure Open and close a random access file

muniya
Download Presentation

Tutorial 10 Random Access Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 10Random Access Files

  2. Random Access FilesLesson A Objectives After completing this lesson, you will be able to: • Define the terminology used with random access files • Create a record structure • Open and close a random access file • Write data to and read data from a random access file • Initialize a random access file • Test for the end of a random access file

  3. Random Access Files Versus Sequential Access Files • A random access file is composed of fields and records • A field is a single item of information about a person, place, or thing • A record is a group of related fields that contain all of the necessary data about a specific person, place, or thing • Each record in a random access file also has a unique number, called a record number, that indicates its position in the file

  4. Records and Fields • You can directly access a record in a random access file by its record number • For this reason, random access files also are referred to as direct access files A set of student records

  5. Creating a Record Structure • Each record in a random access file must contain the same number of fields • You ensure that each record contains the exact same fields by creating a record structure • The record structure itself actually becomes a data type, called a user-defined data type, which is separate and distinct from the standard data types available in Visual Basic .NET • You use the Structure statement to create a record structure in Visual Basic .NET • An attribute is simply an instruction that provides additional information for the Visual Basic .NET compiler

  6. Creating a Record Structure • The Structure statement begins with the keyword Structure followed by the name of the record structure; the statement ends with the keywords EndStructure

  7. Declaring a Record Variable • A record variable will itself contain one or more variables called field variables • You separate the record variable’s name from the field variable’s name with a period • Declare the variable Dim udtEmploy As EmployStruc • Referring to the field variables udtEmploy.intEmployNumber udtEmploy.strFirstName udtEmploy.strLastName udtEmploy.sngSalary A User-Defined Data Type

  8. Opening a Random Access File • In Visual Basic .NET, you use the FileOpen function to open either a new random access file or an existing random access file

  9. Writing Records to a Random Access File • You use the FilePut function to write a record to a random access file

  10. Initializing a Random Access File Declare a variable Initialize field variables Open file Write records

  11. Reading Records from a Random Access File • You use the FileGet function to read a record from a random access file

  12. Testing for the End of a Random Access File • You can use the EOF function, which stands for “end of file,” to determine whether the file pointer is at the end of a random access file

  13. Closing a Random Access File • You use the FileClose function to close a random access file

  14. Using a Random Access File in an ApplicationLesson B Objectives After completing this lesson, you will be able to: • Use a record structure in an application • Initialize a random access file in an application • Add records to a random access file • Display a specific record contained in a random access file • Verify that the record number is valid

  15. Coding the InitializeButton Click Event Procedure • Figure 10-4 shows the pseudocode for the Initialize File button’s Click event procedure

  16. Coding the AddButtonClick Event Procedure • The AddButton Click event procedure is responsible for adding a participant record to the random access file • Figure 10-18 shows the pseudocode for the AddButton Click event procedure

  17. Coding the DisplayButton Click Event Procedure • The DisplayButton Click event procedure is responsible for displaying the record associated with a specific seat number • Figure 10-23 shows the pseudocode for the DisplayButton Click event procedure

  18. Completing the Seminar ApplicationLesson C Objectives After completing this lesson, you will be able to: • Delete the information from a record stored in a random access file • Print the contents of a random access file

  19. Coding the Remaining Procedures in the Seminar Application • You need to code the Click event procedures for the RemoveButton and PrintButton controls, and the PrintPage event procedure for the SeminarPrintDocument control

  20. Coding the RemoveButtonClick Event Procedure • The RemoveButton Click event procedure is responsible for removing a record from the participants.data file • Figure 10-27 shows the pseudocode for the RemoveButton Click event procedure

  21. Coding the PrintButton Click Event Procedure • The PrintButton Click event procedure is responsible for using the SeminarPrintDocument control to print the contents of the random access file

  22. Coding the SeminarPrintDocument PrintPage Event Procedure • The SeminarPrintDocument control’s PrintPage event procedure is responsible for printing the Seminar Participant Report • The report should contain three columns of information • The first column should list 20 seat numbers, and the second and third columns should list the corresponding participant and company names, which are stored in the participants.data file

More Related