Login | |
|
 |
"stopping" text stream operation - 2/15/2007 12:26:06 PM
|
|
 |
|
| |
marcusrp
Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
|
Ok guys, I think I need a kickstart to my brain. The highlighted section I'm trying to do some logic right after finding a string before going on to the next line in the file. But the instr function keeps on going (keeps processing the text stream) without going to the if statements first. How do I get it to perform the inner if statement logic before proceeding to the next line? Thanks. NOTE: the inner if statements were added to a script I had already written before to add functionality, so if someone wants to tell me I need to rewrite my script, feel free, I think I'm experiencing a block and may need to be told it needs to be done a different way. Const ForReading = 1, ForAppending = 8, ForWriting = 2 Set objLog = CreateObject("Scripting.FileSystemObject") Set objNewFile = objLog.OpenTextFile("z:\scripts\logs\cert_ssl.txt", ForAppending, True) Set objOldFile = objLog.OpenTextFile("z:\scripts\logs\bigeventLogRSI7_2.txt", ForReading, True) n = 0 Do While objOldFile.AtEndOfStream <> True strLine = objOldFile.Readline If InStr(strLine, "encryption") Then if n < 5 then objNewFile.WriteLine(strLine) end if if objOldFile.AtEndOfStream = True then objNewFile.Writeline("This message repeats" & n & "times in this log file!") end if n = n + 1 end if Loop wscript.echo "Script is done!"
|
|
| |
|
|
|
 |
RE: "stopping" text stream operation - 2/16/2007 5:02:38 AM
|
|
 |
|
| |
dm_4ever
Posts: 2359
Score: 36
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Is this the part that never gets executed: if n < 5 then objNewFile.WriteLine(strLine) end if Could it be that by the time you find the string you're past 5 already?
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: "stopping" text stream operation - 2/18/2007 12:08:43 PM
|
|
 |
|
| |
marcusrp
Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
|
That worked great. Thanks DiGiTAL.SkReAM! I only had to swap the count variable, it was using the array counter for comparison ( the array contains ALL of the elements of the file, so wont increment sequentially from 0 because the string might be anywhere in the collection and the counter would start from whatever array position it finds the string). Dim oFSO, aOldFileLine, n, iFoundCount iFoundCount = 0 Set oFSO = CreateObject("Scripting.FileSystemObject") aOldFileLine = Split(oFSO.OpenTextFile("c:\test\bigeventLogRSI14_2.txt",1).ReadAll,VbCrLf) For n = 0 To UBound(aOldFileLine) If InStr(aOldFileLine(n),"encryption") <> 0 Then If iFoundCount < 5 Then oFSO.OpenTextFile("c:\test\cert_ssl.txt",8).WriteLine aOldFileLine(n) End If iFoundCount = iFoundCount + 1 End If Next oFSO.OpenTextFile("c:\test\cert_ssl.txt",8).WriteLine "This message repeats" & iFoundCount & "times in this log file!" WScript.Echo "Script is done!"
|
|
| |
|
|
|
 |
RE: "stopping" text stream operation - 2/18/2007 6:28:19 PM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1139
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Glad it worked for you.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
|
|