How to read a text file in VB 6
-
Hello, Can any body tell me how to read a text file in visual basic 6.The file contains the data not more then 2k. Thanks in advance,
Public Function ReadTextFile(sFileName As String) As String Dim iFileNum As Integer Dim bFileOpen As Boolean ' Activate error trapping. On Error GoTo Catch ' Read text file. ReadTextFile = "" iFileNum = FreeFile Open sFileName For Input Access Read As #iFileNum bFileOpen = True ReadTextFile = Input(LOF(iFileNum), iFileNum) Close #iFileNum bFileOpen = False Exit Function Catch: ' An error occurred. This will happen if file was not found. If bFileOpen Then Close #iFileNum End Function Public Sub Test() Dim sText As String sText = ReadTextFile("c:\MyPath\MyFile.txt") End Sub
-- modified at 14:07 Monday 14th November, 2005