Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object variable not set error

Status
Not open for further replies.

vbcdor

Technical User
Jan 27, 2004
39
US
Hi, I hope someone can help me with a script I'm trying to write. I don't know much about vbscript, but I'm trying to piece together a script that will look in a Window 2000 event log, for 1 day and write to a text file when it finds certain events. I get sporatic results with this script. Sometimes it writes the data to the text file ok and other times it doesn't, but I'm getting an error that an object variable is not set and it's pointing to the first Writeline statement. Any ideas anyone?
Thanks.

Dim fso, f1
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\temp\testfile.txt", True)
dtmEndDate = CDate(Date)
dtmStartDate = dtmEndDate - 1


' Converting to WMI "date"
dtmEndDate = Year(dtmEndDate) _
& Right( "00" & Month(dtmEndDate), 2) _
& Right( "00" & Day(dtmEndDate), 2)

dtmStartDate = Year(dtmStartDate) _
& Right( "00" & Month(dtmStartDate), 2) _
& Right( "00" & Day(dtmStartDate), 2)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "EventCode = '1704' and TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For each objEvent in colLoggedEvents
f1.WriteLine "got to here"
f1.WriteLine "Oracle DB shutdowns: " & colLoggedEvents.Count
f1.WriteLine "Message: " & objEvent.Message
f1.WriteLine "Time Written: " & objEvent.TimeWritten
f1.WriteLine "*********"
f1.WriteBlankLines(1)
f1.Close
Next

 
Instead of:
f1.Close
Next
Try this:
Next
f1.Close


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV,

Thanks, I think that did it. I had changed this before and sometimes I would only get the first line written and other times I would get the entire file written so I thought that it wasn't working. But I think I just was not waiting long enough to go back into the textfile to check. I went into the textfile right after the date/time stamp changed, but I noticed that after testing for awhile, that first the date/time stamp changes, then it takes a few more seconds before the actual size of the textfile changes.
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top