Adding a logfile to your VBS scripts

Share your tips, tricks and favorite iMacros macros, scripts and applications for web automation in general here.

Moderator: iMacros Moderators

Adding a logfile to your VBS scripts

by Hannes, Tech Support on Thu Oct 18, 2007 12: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
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2120
Joined: Thu Sep 21, 2006 6:27 am

Return to How-To's and useful iMacros: All other topics

Who is online

Users browsing this forum: No registered users and 1 guest

-->