Jump to content
Heads Up! This website is no longer maintained, if your a member from our era, consider joining the discord to say hello.
Sign in to follow this  

Writing And Reading To And From Files.

Recommended Posts

Some people don't know how to do this... lmao.

 

I included 3 functions:

 

Writelog

Writefile

Readfile

 

Obviously you should be able to figure out what they do. I also included an example usage. Just copy this code into a module.

 

*Note for Writelog*

Memory Killer because it opens and closes the file every time you use it. You can reprogram it for your own purposes :D

 

'Written by: HookE
'http://www.Ghoztcraft.net

Public Function WriteLog(FilePath As String, Text As String)

  On Error Resume Next

  Open (FilePath) For Append As #1

     Print #1, Text

  Close #1

End Function

Public Function WriteFile(FilePath As String, Text As String)

  On Error Resume Next

  Open FilePath For Output As #2

     Print #2, Text

  Close #2

End Function

Public Function ReadFile(FilePath As String) As String

  On Error Resume Next

  Open FilePath For Input As #3

     ReadFile = Input(LOF(3), 3)

  Close #3

End Function

'Example Usage

Sub Main()

  WriteFile App.Path & "Test.txt", "Write File Test"

  MsgBox ReadFile(App.Path & "Test.txt"), vbInformation, "Read File Test"

  WriteLog App.Path & "Log.txt", "Testing Complete"

End Sub

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×