The Open StatementSequential files and random-access files share common features. You use Open for both file types. The kind of file access you achieve with Open depends on the arguments you use in the Open statement. Open reserves a file handle, also called a channel, for reading from and writing to a file. The Open statement associates a number to the handle. When this file handle is open, the data stream can flow. The mode in which you open the file number[md]read, write, or both[md]dictates how the data stream can flow between the file and the computer.
Here's the Open statement's format: Open strFileName [For Mode] [AccessRestriction] [LockType] As [#]intFileNum [Len = intRecordLength]
All Open statements must include the filename and file number arguments, but the other arguments are optional. A simple call to Open with only the required parameters might look like this: Open "aFile.Txt" As #1 This statement opens a file named aFile.Txt as file number 1. To reference this file for input or output, you reference the file number. This file has been opened in random-access mode, because the default when you omit the For Mode portion is Random. All the commands in today's lesson work with text files. This lesson uses the filename extension .txt or .dat, two commonly used extensions for text files. |
|
![]() |
![]() |
|||