Traditional Visual Basic File Management

Visual Basic has included significant file management features since its first release. In fact, there are more features in Visual Basic that deal with file and directory manipulation than with pretty much anything else.

Most of the functions that allow you to read and modify file content use a file handle, a numeric identifier that refers to a specific open file. This file handle is generated with the FreeFile function, and must be obtained before calling any of the traditional Visual Basic file features.

Dim fileID As Integer fileID = FreeFile() FileOpen(fileID, "C:\TestData.txt", OpenMode.Append) PrintLine(fileID, "Important output to file.") FileClose(fileID) 

File handle-based file manipulation works just fine, but it is so early-'90s. It's not really a .NET technology, and is not object-based at all (unless you consider that an Integer is an object). Therefore, we won't be covering it in this book, or using it in the Library Project. Table 15-1 lists the major Visual Basic features that use file handles. If you need to know about the handle-based features in Visual Basic, or if your work involves migrating pre-.NET Visual Basic applications, use this table to help you locate full feature details in the technical documentation supplied with Visual Basic.

Table 15-1. Visual Basic Features That Use File Handles




Returns a Boolean indicating whether the current position in the file is at or past the end of the file. Use this function to determine when to stop reading existing data from a file.


Indicates the file attributes currently set on an open file handle.


Closes a specific file opened using a file handle.


Retrieves structured data from a file and stores it in a matching object.


Same as FileGet, but with slightly different data typing support.


Opens a file for input or output.


Writes an object to a file in a structured manner.


Same as FilePut, but with slightly different data typing support.


Sets the default line width for formatted text output files.


Returns the next available file handle.


Retrieves a value previously written to a file using Write or WriteLine.


Retrieves a specific number of characters from an input file.


Returns a complete line of input from a file.


Returns the current byte or record location in the file.


Locks a file or specific records in a file so that others cannot make changes.


Returns the length of an open file, in bytes.


Sends text output to a file.


Sends text output to a file, ending it with a line terminator.


Closes all files currently opened with file handles.


Gets or sets the current position in a file.


This function helps format text for output to columnar text files.


This function helps format text for output to columnar text files.


Removes locks previously set with Lock.


Writes data to a file using a consistent format that can be easily read later.


Same as Write, but ends the output with a line terminator.

Start-to-Finish Visual Basic 2005. Learn Visual Basic 2005 as You Design and Develop a Complete Application
Start-to-Finish Visual Basic 2005: Learn Visual Basic 2005 as You Design and Develop a Complete Application
ISBN: 0321398009
EAN: 2147483647
Year: 2006
Pages: 247
Authors: Tim Patrick

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: