Create log file

3 posts / 0 new
Last post
Robert van den ...
Offline
Joined: 08/08/2018 - 07:37
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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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
Offline
Joined: 02/15/2017 - 11: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