Hi Rick,

I use a slight variation of Steve's examples which I show below.  I have a 
boolean variable, which can be a constant or read in from a .ini file, which 
indicates if the app is in debug mode or production mode.  This allows me to 
leave all my debug statements in place, not have them do anything most of the 
time, but I can easily turn them on (or have a user do so if she's having an 
issue with my app).

I also add a time indication, to show me how many seconds pass between each log 
message (so I can see if something is taking longer than expected):


Dim goOutputDebugFile
Dim productionRelease


set goOutputDebugFile = nothing
 productionRelease = false


Sub debugMsg(ByVal Text)
' called to add a debug message if debugging is enabled

If productionRelease Then Exit Sub

On Error Resume Next
If goOutputDebugFile Is Nothing Then
Set goOutputDebugFile = SharedObjects("com.GWMicro.GWToolkit.OutputDebugFile", 
60 * 1000).NewFile
If goOutputDebugFile Is Nothing Then
MsgBox "unable to get GW toolkit output debug file object", vbOKOnly + 
vbCritical + vbMsgBoxSetForeground, clientInformation.ScriptName
stopScript
End If '  goOutputDebugFile Is Nothing
goOutputDebugFile.filename = Profiles.active.Path & "\log.txt"
End If '  goOutputDebugFile Is Nothing


goOutputDebugFile.Write Int(Timer) & ": " & Text

End Sub





Chip Orange
Florida Public Service Commission
Computer Systems Analyst
850-413-6314


-----Original Message-----
From: Scripting 
[mailto:[email protected]] On 
Behalf Of Rick Thomas via Scripting
Sent: Thursday, March 19, 2015 5:35 AM
To: 'Window-Eyes Scripting List'
Subject: Simple Log File VbScript

I want to create a method to append lines to a text file:

The first code I pulled from google:

To create a simple log file for debugging Aarons script:

DIM logFSO, logFile

Set logFSO = CreateObject("Scripting.FileSystemObject")

Set logFile = logFSO.CreateTextFile( "c:\VSScriptLog.txt", True)

[Above just goes high in the script to be executed once when loaded]

logFile.WriteLine("Logged ok") 

[Above goes wherever i want to print a line to the log]

logFile.Close 

 [Where do I put the close for the file in a script so it closes when the
script is done]

Or with the file options can i just have a method:

High in code:

DIM logFSO, logFile

Set logFSO = CreateObject("Scripting.FileSystemObject")

Then:

in a print Sub:

Set logFile = logFSO.CreateTextFile( "c:\VSScriptLog.txt", True)

logFile.WriteLine("Logged ok") 

logFile.Close 

End Sub

I want to just append lines to a text file upon a WriteLine method of the
fso object for debugging.

Rick USA

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com/attachments/20150319/530eede4/attachment.htm>
_______________________________________________
Any views or opinions presented in this email are solely those of the author 
and do not necessarily represent those of Ai Squared.

For membership options, visit 
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/corange%40psc.state.fl.us.
For subscription options, visit 
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at 
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com
_______________________________________________
Any views or opinions presented in this email are solely those of the author 
and do not necessarily represent those of Ai Squared.

For membership options, visit 
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/archive%40mail-archive.com.
For subscription options, visit 
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at 
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com

Reply via email to