|
|
|
The fastest way to read a text file is using the Input$ function, as shown in this reusable procedure: |
Click here to copy the following block | Function FileText (filename$) As String Dim handle As Integer handle = FreeFile Open filename$ For Input As #handle FileText = Input$(LOF(handle), handle) Close #handle End Function |
This method is much faster than reading each single line of the file using a Line Input statements. Here's how you can load a multiline textbox control with the contents of Autoexec.bat: |
UPDATE: Andrew Marshall wrote us to point out that the above routine fails when the file includes a Ctrl-Z (EOF) character, so we prepared a better version that works around that problem:
|
Click here to copy the following block | Function FileText(ByVal filename As String) As String Dim handle As Integer If Len(Dir$(filename)) = 0 Then Err.Raise 53 End If handle = FreeFile Open filename$ For Binary As #handle FileText = Space$(LOF(handle)) Get #handle, , FileText Close #handle End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|