Home -> Programming -> Storage -> File Operations

File Operations

One of the most useful features that a computer program can have is the ability to save information created during one session for later use in a subsequent session. We call this saved information data files. Visual Basic offers several ways of doing this. In this page we will review the basics of file operations and in the following pages we will go through the details of how to implement the reading and writing of data files.

To begin with there are several terms you need to know to understand file operations. Data files are usually organized in two main ways.

  1. Sequential text files: these files are also called Text Files because they consist of unicode characters: text, numbers and punctuation which when viewed are easy to read and understand. They are created by storing one character after another from the beginning of the file until the end of the file. They can only be accessed by reading from the beginning of the file until we arrive at the particular information we are interested in. This is, of course, awkward for large data files but for small ones the performance is acceptable.
  2. Random files: these files are like the former except that we break the files up into records and fields. Each record is comprised of one or more fields, and each record is the same length. By doing this we can access our information record by record. Hence the name "Random" to describe that we can jump from one given point in the file to another. In fact we can only jump to the start of any particular record, we cannot start reading or writing a file in the middle of a record.

Visual Basic has two methods by which files are handled. The first uses File Streams to read and write data to and from files. The next two pages will show you how to do this with Sequential and Random files. The second method uses a new coding procedure to read all or write all the data at once. This is very useful for small files. There is a disadvantage to this which will be discussed in that section.