VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Read / Write - Open / Close text files. This code is short, quick, and concise. If you have any pro

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,

Rate Read / Write - Open / Close text files. This code is short, quick, and concise. If you have any pro



'-- 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

Download this snippet    Add to My Saved Code

Read / Write - Open / Close text files. This code is short, quick, and concise. If you have any pro Comments

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.

Post your comment

Subject:
Message:
0/1000 characters