Visual Basic provides a number of commands for manipulating the filesystem. These commands are relatively flexible and easy to understand. Most of them have been around since the early days of Visual Basic, so many long-time Visual Basic developers prefer to use them rather than the newer .NET Framework methods.
One disadvantage to these methods is that they do not natively allow you to read and write nonstandard data types. They can handle string, date, integer, long, single, double, and decimal data. They can also handle structures and arrays of those types. They cannot, however, handle classes themselves. You can use XML serialization to convert a class object into a string and then use these methods to read and write the result, but that requires an extra step with some added complexity.
The section “File System Methods” later in this chapter describes the native filesystem methods of Visual Basic. The sections “Sequential-File Access,”“Random-File Access,” and “Binary-File Access” later in this chapter describe specific issues for working with sequential, random, and binary files.
The following table describes the methods Visual Basic provides for working with files:
|EOF||Returns True if a file open for reading is at the end of file. (EOF stands for End Of File.)|
|FileClose||Closes an open file.|
|FileGet||Reads data from a file opened in Random or Binary mode into a variable.|
|FileGetObject||Reads data as an object from ...|