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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to create a log file

Status
Not open for further replies.

Ankor

Programmer
Mar 21, 2002
144
US
Hello all!

Does anybody know the way to create some king of a log file and send data to it from the web page. In other words, I want to be able to send my data not to the SQL or Access table, but to the .txt or .csv file. Every new record should be appended to the existing list. The whole point of having this code is to have a backup of the tables that are already connected to this web page. On the other hand, I don't want to have another table in SQL that will store the backup. Is there a way?

I appreciate your ideas.
 


Ankor,

You can use this function to log a string to a file,

fengshui_1998



LogFile = "C:\Mydir\MyLogFile.txt"
strMsg = "Test string to log file"

Log_Report( LogFile, strMsg)

' *********************************
Sub Log_Report(strFile, LogMsg)
' *********************************
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set Fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FileExists(strFile) then
Set objRpt = fso_OpenTextFile(strFile, ForWriting, TRUE)
Else
Set objRpt = fso_OpenTextFile(strFile, ForAppending, TRUE)
End If
objRpt.write LogMsg
objRpt.writeblanklines(1)
objRpt.close
Set objRpt = Nothing

End Sub
 
Hmmmm.... Again, here is a code:
If NOT fso.FileExists(strFile) then
Set objRpt = fso_OpenTextFile(strFile, ForWriting, TRUE)
Else
Set objRpt = fso_OpenTextFile(strFile, ForAppending, TRUE)
End If


Doesn't it mean that if the file does not exist, then the code creates it in any case (TRUE)? Since the first time we create the file and open it ForWriting, this TRUE clouse is not needed in the second case? Isn't it?

Thank you for your help!
Ankor
 
Ankor,

Sorry, I overlooked the meanigng of TRUE. You can just use this statement

Set objRpt = fso_OpenTextFile(strFile, ForAppending, TRUE)

fengshui_1998
 
I got it. Thanks. Your advise was very useful.

Ankor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top