Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


"stopping" text stream operation

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,43265
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> "stopping" text stream operation
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 "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!"
 
 
Post #: 1
 
 RE: "stopping" text stream operation - 2/15/2007 5:06:06 PM   
  dm_4ever


Posts: 2359
Score: 36
Joined: 6/29/2006
From: Orange County, California
Status: offline
Is encryption in lower case in the text file? What if you tried If InStr(LCase(strLine), "encryption") Then

_____________________________

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

(in reply to marcusrp)
 
 
Post #: 2
 
 RE: "stopping" text stream operation - 2/16/2007 4:51:24 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
I'm not having any issues finding the string. My problem is that once it finds an instance of the string, I want to perform the logic in the if statements before it goes to the next instance of the string, and that never happens cuz the instr function never passes control to the next line, it just keeps finding that string till it gets to the end of the file. If you dont get my meaning,  I inserted a wscript.echo "found string" line right after the If InStr(strLine, "encryption") Then line and once it gets to that line it keeps displaying "found string" for every instance of the word "encryption" until it reaches the end of the file, THEN it does the if statements, which by then is too late. I think maybe I might want to use something besides a do-while loop for the text stream processing, but my brain was pretty fried last night so couldnt get past it. thanks for any help.

(in reply to marcusrp)
 
 
Post #: 3
 
 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

(in reply to marcusrp)
 
 
Post #: 4
 
 RE: "stopping" text stream operation - 2/16/2007 5:43:12 AM   
  DiGiTAL.SkReAM


Posts: 1139
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
Give this a shot:

      


_____________________________

"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

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: "stopping" text stream operation - 2/16/2007 8:17:53 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
dm_4ever: The logfile is not being written to at all even though I know its finding the string, so it cant be entering the portion where it writes out results, thus the count also cannot be incrementing. Again though, i know its not entering the inner if statements based on what I stated earlier. Thanks for the feedback though.

DiGiTAL.SkReAM: This might help. I thought I might have to use some sort of collection or array, just couldnt get it going in my head...I'll play with that. I have to get the results out today though by hook or crook, so will probably leave off the fancy message truncation part for the immediate results and just output everything, even though its really HUGE. oh well. will update the thread with the results (once i get time to play with the added functionality). thanks!

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 6
 
 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!"

(in reply to marcusrp)
 
 
Post #: 7
 
 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

(in reply to marcusrp)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> "stopping" text stream operation Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts