Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone know how to easily write to a log file 1

Status
Not open for further replies.

ghost2

Programmer
Aug 7, 2003
145
US
I have alot of code to write to a file but I was looking for the simplest way to just open a text file and write to it and if it exists then append to it. Anyone have any example code? Thanks all
 
This append to a file (creates it if it doesn't exist)
Code:
Public Sub Log(ByRef strLogtext As String)

    Dim objFSO As Scripting.FileSystemObject
    Dim objStream As TextStream
    
    Set objFSO = New Scripting.FileSystemObject
    Set objStream = objFSO.OpenTextFile("c:\TEMP\log.txt", ForAppending, True)
    objStream.Write strLogtext & vbCrLf
    objStream.Close
    
    Set objStream = Nothing
    Set objFSO = Nothing

End Sub
 
Oh I forgot: add a reference to Microsoft Scripting Runtime.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top