by Patrick R. Daniel (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 6th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Read / Write - Open / Close text files. This code is short, quick, and concise. If you have any problems with it, let me know... or fix it,
'-- Contact me at: [email protected]
Public Function ReadFile(strPath As String) As String
On Error GoTo eHandler
Dim iFileNumber As Integer
Dim blnOpen As Boolean
iFileNumber = FreeFile
Open strPath For Input As #iFileNumber
blnOpen = True
ReadFile = Input(LOF(iFileNumber), iFileNumber)
eHandler:
If blnOpen Then Close #iFileNumber
If Err Then MsgBox Err.Description, vbOKOnly + vbExclamation, Err.Number & " - " & Err.Source
End Function
Public Function WriteFile(strPath As String, strValue As String) As Boolean
On Error GoTo eHandler
Dim iFileNumber As Integer
Dim blnOpen As Boolean
iFileNumber = FreeFile
Open strPath For Output As #iFileNumber
blnOpen = True
Print #iFileNumber, strValue
eHandler:
If blnOpen Then Close #iFileNumber
If Err Then
MsgBox Err.Description, vbOKOnly + vbExclamation, Err.Number & " - " & Err.Source
Else
WriteFile = True
End If
End Function
No comments have been posted about Read / Write - Open / Close text files. This code is short, quick, and concise. If you have any pro. Why not be the first to post a comment about Read / Write - Open / Close text files. This code is short, quick, and concise. If you have any pro.