Adding a logfile to your VBS scripts

Share your tips, tricks and favorite iMacros macros, scripts and applications for web automation in general here.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team
Post Reply
Hannes, Tech Support

Adding a logfile to your VBS scripts

Post by Hannes, Tech Support » Thu Oct 18, 2007 7:34 am

The following script contains the necessary lines of code to add logging to an VBS script. Please note that in "real world" applications, the logging should be linked to the iMacros methods' return values (i.e. they should reflect whether a command was performed successfully).

Here's how the script's simple log looks like when run only once:

Code: Select all

10/18/2007 9:11:55 Startup 
Init...Done
Running macro "#Current"...Done
And here's the script:

Code: Select all

Option Explicit
Dim LOG_FILE

' global settings
LOG_FILE="C:\Documents and Settings\All Users\Documents\iMacros\Downloads\script.with.logging.log" 

' File access constants
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8 

'open log file for appending
Dim objFileSystemLog,logFile
Set objFileSystemLog = CreateObject("Scripting.fileSystemObject")
Set logFile = objFileSystemLog.OpenTextFile(LOG_FILE, FOR_APPENDING, true)


'initialize iMacros instance
Dim iim1, iret
loggingLine(vbNewLine+vbNewLine + Cstr(now()) + " Startup ")

logging("Init...")
set iim1= CreateObject ("imacros")
iret = iim1.iimInit ("",TRUE)
loggingLine("Done")

logging("Running macro ""#Current""...")
iret = iim1.iimPlay("#Current")
loggingLine("Done")


'##############
'# end of main script
'##############

sub logging (myText)
	logFile.write(myText)
end sub 'logging

sub loggingLine (myText)
	logFile.write(myText+vbNewLine)
end sub
Post Reply