Log, Logtext, and Sayit

by Jeff Medkeff

These are the three fundamental logging functions that are used in the modular routines. All three will print the logged text to the console window. They differ as follows:



' Header stuff. The logging is a special case, and is
' discussed some on the Headers and Conventions page, but
' it bears more detailed treatment here.

' You need to make logFSO and logStream global to use it 
' conveniently. So put this BEFORE your sub main()

dim logFSO
dim logStream








' this creates the objects and goes near the beginning
' of sub main(), or close to the beginning of whatever
' subroutine begins execution of your script.

Set logFSO = CreateObject("Scripting.FileSystemObject")

' Next, we figure out where to put our log file. I use a
' user-settable constant called logDir for the log directory.
' session is the first four digits and two decimal places of the
' Julian Date at the time this code executes:

' figure out the session number:
session = tools.JDPrefix(CStr(Util.SysJulianDate))

' construct the filename:
fn = logDir & "\" & session & ".log"

' create and open the log file for writing:
Set logStream = logFSO.CreateTextFile(fn.True)









' Here are the log functions, which go outside sub main()

' TimeUTC is provided by ACP

Sub Log(t)
' Logs and speaks text
    Console.PrintLine t
    logStream.WriteLine FormatDateTime(TimeUTC(), 4) & " " & t
    If Voice.Active Then Voice.Speak t
End Sub

Sub Logtext(t)
' Logs but does not speak text
    Console.Printline t
    logStream.WriteLine FormatDateTime(TimeUTC(), 4) & " " & t
End Sub

Sub Sayit(t)
' Says but does not log text
    Console.Printline t
    If Voice.Active Then Voice.Speak t
End Sub