HPvH
asked on
VBS Create CSV Log file
Hi,
I need a function who write a csv log file.
I want to call my function like this:
WriteLog(DateTime,Value1,V alue2,Valu e3)
Every time I call WriteLog, it should append the data to c:\temp\LogFile.csv
Thanks!
HPvH
I need a function who write a csv log file.
I want to call my function like this:
WriteLog(DateTime,Value1,V
Every time I call WriteLog, it should append the data to c:\temp\LogFile.csv
Thanks!
HPvH
Hi,
Try the following!
You can set the objFSO in the main script. You can set them in the function too but then he opens and closes them each time you enter the function.
DateTime, Value1, Value2, Value3 are all expected to be variables you get on your own :P
Regards,
M
Try the following!
You can set the objFSO in the main script. You can set them in the function too but then he opens and closes them each time you enter the function.
DateTime, Value1, Value2, Value3 are all expected to be variables you get on your own :P
Regards,
M
SET objFSO = CreateObject("Scripting.FileSystemObject")
SET objOutputFile = objFSO.CreateTextFile("log.txt", True)
Function Writelog(DateTime, Value1, Value2, Value3)
objOutputfile.writeline DateTime & "," & Value1 & "," & Value2 & "," & Value3
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public Sub WriteFileText(ByVal FileName As String, ByVal Source As String, Optional noCrlf As Boolean = False, Optional Append As Boolean = False)
On Error GoTo EHandler
Dim Handle As Integer
Handle = FreeFile
If Append Then
Open FileName For Append As #Handle
If noCrlf Then
Print #Handle, Source;
Else
Print #Handle, Source
End If
On Error Resume Next
Close #Handle
Else
Open FileName For Output As #Handle
If noCrlf Then
Print #Handle, Source;
Else
Print #Handle, Source
End If
On Error Resume Next
Close #Handle
End If
Exit Sub
EHandler:
'ShowErrMsg
On Error Resume Next
Close #Handle
End Sub