HTA Logging



This is a really simple function, but quite useful nevertheless due to its flexibility. In essence, this is a logging function (used by other HTA snippets of mine).

It requires several variables: logfile, logline, gui, append, msgtype.

Logfile is a path to a file to which we want to write something.

Logline is what we want to write.

GUI is, practically, a flag. If set to 1 or empty it will use Logline to output the same to script's interface (statusbar in my case). If set to any string - that string will be used instead. If set to 0 - nothing will be shown.

Append is a standard flag to determine whether we overwrite the log file or append to it. Same as with built in function.

MSGType governs a message box. Very useful for notifying about errors. If it's set to 0 - nothing will be shown. If it's set to 1 - an Information message box will be shown, if set to 2 - Warning and if to 3 - Error.


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' Writing to file

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Function writeinfile(logfile, logline, gui, append, msgtype)

dim writelog

On Error Resume Next

If cstr(gui) = "1" or cstr(gui) = "" Then

statusbar.value = logline

elseif cstr(gui) = "0" Then

'Do Nothing

else

statusbar.value = gui

End if

On Error GoTo 0

Set writelog=objFSO.openTextfile(logfile, append, true)

writelog.WriteLine logline

writelog.close

On Error Resume Next

if cstr(gui) "0" Then

if msgtype = 1 Then

msgbox statusbar.value, vbOKOnly+vbInformation, "Info"

elseif msgtype = 2 Then

msgbox statusbar.value, vbOKOnly+vbExclamation, "Warning"

elseif msgtype = 3 Then

msgbox statusbar.value, vbOKOnly+vbCritical, "Error"

End if

End if

On Error GoTo 0

End Function

[Snippets]