Skip to main content

Create log file

At the moment i'am using the On Error Resume a lot, but is it possible when the err.number is not equal to 0 that a text line is exported to a txt file? That way i can create a log. Because with the automate of IDEA server scripts i can't use msgboxes anymore.

Brian Element Mon, 05/20/2019 - 11:16

Hi Robert, you can use the FileSystemObject to write files.  Here is some sample code.  There is lots of information on using this if you do a google search.  You can create the log at the beginning of the file and just use the .WriteLine to add text as you go along and then close the file when the script is completed.  I do this sometimes to keep track of information instead of the msgbox.


Sub Main
	Dim fs As Object
	Dim a As Object
	Dim sProject As String
	sProject = Client.WorkingDirectory()
	Set fs = CreateObject("Scripting.FileSystemObject")
		Set a = fs.CreateTextFile(sProject & "testfile.txt", True)
	    		a.WriteLine("This is a test.")
	   		 a.Close
	   	Set a = Nothing
   	Set fs = Nothing
End Sub

JHDCC Mon, 09/30/2019 - 06:28

Could anybody point me in the direction of how to log any errors arising during a script and output them to a text file?
I've a large script with IgnoreWarning(True), but it would be helpful to identify any errors or warnings arising from the script.
Unless I'm mistaken (which is a distinct possibility!) it looks like the above vb links in to the tail end of this to create the text file and creates a line "this is a test"... how do I instead get IDEA to populate the file with errors?
Thanks