August 18, 2001

GETting the all contents of a file (reading text file at once.)

To read a complete file in VB, the normal procedure is to read the contents of the file line by line and accumulate it into a string. Instead, you can use the GET function to read the file with a single call. Doing so simplifies and speeds up the process of reading a file.

You can use the following function: (This code involves a single call to return the contents of the file.)

Dim Handle As Integer
Dim FileString As String
Handle = FreeFile
Open "C:\TEMP\AJT.TXT" For Binary As #Handle
FileString = Space(FileLen("C:\TEMP\AJT.TXT"))
Get #Handle, ,FileString
Close #Handle