|
-
Apr 19th, 2005, 01:10 PM
#1
Thread Starter
Addicted Member
If statement [RESOLVED]
I have a loop that goes through a logfile line by line and does certain events if certain strings are in that line. My question is how do I get it to skip to the next line if it contains a certain string? I'm trying to use If statements like below, I'm just not sure how to do it.
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(blah blah) Then
'Do some stuff
End If
If InStr(other blah blah) Then
'Go to next Line
End If
Loop
Last edited by bat711; Apr 19th, 2005 at 01:49 PM.
-
Apr 19th, 2005, 01:16 PM
#2
Lively Member
Re: If statement
Just allow it to go to the loop which will move on to the next line. If I misunderstood you, please post a better explanation
-
Apr 19th, 2005, 01:25 PM
#3
Thread Starter
Addicted Member
Re: If statement
Actually now that I look at my example it was a bad one, sorry...
It's nested actually, would look more like this:
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(1, strReadLine, "S ") Then
If InStr(1, strReadLine, "grep") Then
'Go to next Line
End If
If InStr(1, strReadLine, "/") Then
'Do some events
End If
End If
Loop
So how do I get it out of that nested If?
-
Apr 19th, 2005, 01:33 PM
#4
Re: If statement
If I understand you correctly, you can just use an ELSE
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(1, strReadLine, "S ") Then
If InStr(1, strReadLine, "grep") Then
'Go to next Line
else
If InStr(1, strReadLine, "/") Then
'Do some events
End If
endif
End If
Loop
-
Apr 19th, 2005, 01:40 PM
#5
Re: If statement
Why not just do
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(1, strReadLine, "S ") Then
If InStr(1, strReadLine, "grep") Then
'Go to next Line
Loop
End If
If InStr(1, strReadLine, "/") Then
'Do some events
End If
End If
Loop
-
Apr 19th, 2005, 01:44 PM
#6
Addicted Member
Re: If statement
I'm not sure if I get you either, but if I do, something like this would work:
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(1, strReadLine, "S ") Then
If InStr(1, strReadLine, "/") Then
'Do some events
ElseIf InStr(1, strReadLine, "grep") <= 0 Then
Exit Do
'So unless there's "grep", it won't continue.
End If
End If
Loop
-
Apr 19th, 2005, 01:46 PM
#7
Thread Starter
Addicted Member
Re: If statement
Ok, using the else statement worked, thanks. Hack, I'm not sure that would work for my case because if "grep" is in the line I don't want to do anything with it or than go to the next line and it shouldn't be in the file more than once.
Thanks guys.
-
Apr 19th, 2005, 01:49 PM
#8
Frenzied Member
Re: If statement
 Originally Posted by bat711
I have a loop that goes through a logfile line by line and does certain events if certain strings are in that line. My question is how do I get it to skip to the next line if it contains a certain string? I'm trying to use If statements like below, I'm just not sure how to do it.
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(blah blah) Then
'Do some stuff
End If
If InStr(other blah blah) Then
'Go to next Line
End If
Loop
Or keeping your structure the same...
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(blah blah) Then
'Do some stuff
GoTo LoopEnd
End If
If InStr(other blah blah) Then
'Go to next Line
GoTo LoopEnd
End If
LoopEnd:
Loop
P.S. well goto statements are not very good to be used often...
-
Apr 19th, 2005, 01:50 PM
#9
Need-a-life Member
Re: If statement
 Originally Posted by Hack
Why not just do
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(1, strReadLine, "S ") Then
If InStr(1, strReadLine, "grep") Then
'Go to next Line
Loop
End If
If InStr(1, strReadLine, "/") Then
'Do some events
End If
End If
Loop
I think that will only work in C. Are you telling that this code compiles? (I've not tested).
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 19th, 2005, 01:51 PM
#10
Thread Starter
Addicted Member
Re: If statement [RESOLVED]
Yes that is what I was trying to figure out a sort of Go to statement. I Haven't used that since regular BASIC I think.
-
Apr 19th, 2005, 01:51 PM
#11
Need-a-life Member
Re: If statement
I believe the easier way is:
VB Code:
Do While Not EOF(1)
Line Input #1, strReadLine
If InStr(1, strReadLine, "S ") > 0 And InStr(1, strReadLine, "grep") = 0 Then
If InStr(1, strReadLine, "/") Then
'Do some events
End If
End If
Loop
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|