|
-
Sep 17th, 2004, 09:26 AM
#1
Thread Starter
Addicted Member
For...Next jump syntax?(RESOLVED)
Hello all..
working on parsing a large string...and I can't remember the code to test for a certain word in the string, and if it's there, to jump to the next item..
here's the code so far..
Code:
For r = 1 To 85
'code snip...
' now test to see if the word transparent is in the next 50 chars...
' set var to the group of 50 chars
GROUP = Mid(Text6.Text, lnEndPos, 50)
' DEBUG: show group just grabbed
Text13.Text = GROUP
' trap here...
FOUNDIT = InStr(Text13.Text, "transparent")
If FOUNDIT > 0 Then
Text14.Text = FOUNDIT
' found transparent so jump to next iteration
Next r
End If
'code snip here where I parse the string and then save it in a list
next r
When I run this, my error is "Compile error : next without for"
???
Jim
Last edited by JVRudnick; Sep 17th, 2004 at 11:03 AM.
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 09:30 AM
#2
Fanatic Member
Your second IF stament closes outside the FOR ..Next loop this is not allowed all control structures started in a FOR..Next loop must finish inside it..
Hope that helped
Last edited by Bombdrop; Sep 17th, 2004 at 09:42 AM.
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
-
Sep 17th, 2004, 09:48 AM
#3
Thread Starter
Addicted Member
?????????
huh?
I have only 1 If...then statement?
I do not understand your answer...
????
Think of it this way. In a For r = 1 to 85 loop, if I want to test for some string within that loop, how can I "jump" out of that iteration and move to the next r?
???
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 09:52 AM
#4
Fanatic Member
Sorry but what i said about IF staments in For..Next still stands take a look at the following
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim x As Integer
For x = 1 To 100
If x < 10 Then
Debug.Print x
Else
x = 100
End If
Next
End Sub
Hope this helped!!
Useful Links
.Net
#Develop, GhostDoc, CodeKeep , be.PINVOKE, Good Code Snippet Site
Krypton Toolkit, XPCC / XP Common Controls, QSS Windows Forms Components
VB.COM
VB.Classic Help File, MB Controls, MZTools, ADO Stored Procedure Generator add-in,
-
Sep 17th, 2004, 10:00 AM
#5
Thread Starter
Addicted Member
Still confused...
Look....your code is for a button, where the event happens when it's clicked. I do not understand what that has to do with a long 200+ function that I created that goes to a website, grabs ALL the html, and then searches through that string for certain items.
I use a For r = 1 to 85 loop, to build a list that has 85 items in it.
If during that "build" the word "transparent" is found in a certain spot, I wish to NOT add that item to the list.
Hence my little code snippet grabs the next section of the html to check. If it finds the word "transparent" I want to simply skip over the rest of the code where I add that item to my list, and go to the next item to check.
ALL I need is the vb term to jump OUT of this iteration. Using "next r" in that location does not work. Surely, this must be possible -- to test for a conditional, and if TRUE, then jump out of the loop to the next iteration...
Anyone?
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 10:14 AM
#6
Code:
For i = 1 to 50
If somthing > 0 Then
Goto myLabel
End If
' Other code you need to skip
myLabel:
Next i
-
Sep 17th, 2004, 10:17 AM
#7
It seems a simple If Else would work.
VB Code:
For i = 1 to 85
'code snip
If FOUNDIT > 0 Then
Text14.Text = FOUNDIT
' found transparent so jump to next iteration
Else
'code snip here where I parse the string and then save it in a list
End If
Next
-
Sep 17th, 2004, 10:34 AM
#8
Thread Starter
Addicted Member
Cripes....maybe I'm not being clear?
Here's the complete routine to parse the HTML from a web page...
I have included it so you can all see, that I want to be able to TEST for a word (transparent) within a small string, if it is NOT present, then add an item to a list ELSE skip this item and go to the next....
Code:
'Parse HTML page here...
For r = 1 To 85
If lnStartPos > 2 Then
lnStartPos = lnStartPos
Else
lnStartPos = 1
End If
' above checks to see if we've run this once before and if so then leave the
' value of lnStartPos alone, else set it at 1 for the first run thru...
lnStartPos = InStr(lnStartPos, Text6.Text, START)
' start at the end of the delimter...
' Text7.Text = lnStartPos
' DEBUG: just shows the starting position for the grab...
lnStartPos = (lnStartPos + 16)
'add the 10 chars for START and the 4 chars of html
lnEndPos = InStr(lnStartPos, Text6.Text, "</TD>")
' and now run to the end of the proxy...
'TEST here for TRANSPARENT term
'======================================
' set var to the group of 50 chars
GROUP = Mid(Text6.Text, lnEndPos, 50)
' DEBUG: show group just grabbed
Text13.Text = GROUP
' trap here...
FOUNDIT = InStr(Text13.Text, "transparent")
If FOUNDIT > 0 Then
Text14.Text = FOUNDIT
Next r
' **** this does not work!!!!***
' I wish to skip this spot, and go to the next r....
' how do I do that?
End If
lnNumber = (lnEndPos - lnStartPos)
' start minus end for total # of chars to grab....
'GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' grabs the actual proxy...
GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' set var to proxy here
Combo1.AddItem GetListing
' Combo1.Text = GetListing + vbCrLf
' load same into dropdown combo list...
lnStartPos = lnEndPos
' set starting point at new ending point...
GetListing = ""
Next r
I do not know how else to ask for the single vb term that will REJECT this item from the list, and go then go and search for the next item...
While I appreciate no end the help here, everyone has missed the point....
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 10:43 AM
#9
So you want to skip all this code here?
Code:
lnNumber = (lnEndPos - lnStartPos)
' start minus end for total # of chars to grab....
'GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' grabs the actual proxy...
GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' set var to proxy here
Combo1.AddItem GetListing
' Combo1.Text = GetListing + vbCrLf
' load same into dropdown combo list...
lnStartPos = lnEndPos
' set starting point at new ending point...
GetListing = ""
-
Sep 17th, 2004, 10:46 AM
#10
Thread Starter
Addicted Member
Almost...yes!
Yes....that's almost correct....
I will however need to KEEP this part to fuel the return up top to the "next r" with the proper vars...
[code]
lnStartPos = lnEndPos
' set starting point at new ending point...
GetListing = ""
[\code]
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 10:51 AM
#11
Then whats wrong with mine or brucevde's answer?
using my code as a basis
Code:
'Parse HTML page here...
For r = 1 To 85
If lnStartPos > 2 Then
lnStartPos = lnStartPos
Else
lnStartPos = 1
End If
' above checks to see if we've run this once before and if so then leave the
' value of lnStartPos alone, else set it at 1 for the first run thru...
lnStartPos = InStr(lnStartPos, Text6.Text, START)
' start at the end of the delimter...
' Text7.Text = lnStartPos
' DEBUG: just shows the starting position for the grab...
lnStartPos = (lnStartPos + 16)
'add the 10 chars for START and the 4 chars of html
lnEndPos = InStr(lnStartPos, Text6.Text, "</TD>")
' and now run to the end of the proxy...
'TEST here for TRANSPARENT term
'======================================
' set var to the group of 50 chars
GROUP = Mid(Text6.Text, lnEndPos, 50)
' DEBUG: show group just grabbed
Text13.Text = GROUP
' trap here...
FOUNDIT = InStr(Text13.Text, "transparent")
If FOUNDIT > 0 Then
Text14.Text = FOUNDIT
GoTo skiptohere
End If
lnNumber = (lnEndPos - lnStartPos)
' start minus end for total # of chars to grab....
'GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' grabs the actual proxy...
GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' set var to proxy here
Combo1.AddItem GetListing
' Combo1.Text = GetListing + vbCrLf
' load same into dropdown combo list...
skiptohere:
lnStartPos = lnEndPos
' set starting point at new ending point...
GetListing = ""
Next r
or bruces
Code:
'Parse HTML page here...
For r = 1 To 85
If lnStartPos > 2 Then
lnStartPos = lnStartPos
Else
lnStartPos = 1
End If
' above checks to see if we've run this once before and if so then leave the
' value of lnStartPos alone, else set it at 1 for the first run thru...
lnStartPos = InStr(lnStartPos, Text6.Text, START)
' start at the end of the delimter...
' Text7.Text = lnStartPos
' DEBUG: just shows the starting position for the grab...
lnStartPos = (lnStartPos + 16)
'add the 10 chars for START and the 4 chars of html
lnEndPos = InStr(lnStartPos, Text6.Text, "</TD>")
' and now run to the end of the proxy...
'TEST here for TRANSPARENT term
'======================================
' set var to the group of 50 chars
GROUP = Mid(Text6.Text, lnEndPos, 50)
' DEBUG: show group just grabbed
Text13.Text = GROUP
' trap here...
FOUNDIT = InStr(Text13.Text, "transparent")
If FOUNDIT > 0 Then
Text14.Text = FOUNDIT
Else
lnNumber = (lnEndPos - lnStartPos)
' start minus end for total # of chars to grab....
'GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' grabs the actual proxy...
GetListing = Mid(Text6.Text, lnStartPos, lnNumber)
' set var to proxy here
Combo1.AddItem GetListing
' Combo1.Text = GetListing + vbCrLf
' load same into dropdown combo list...
End If
lnStartPos = lnEndPos
' set starting point at new ending point...
GetListing = ""
Next r
-
Sep 17th, 2004, 10:56 AM
#12
Thread Starter
Addicted Member
So
what you're telling me is that in VB there is no way to "jump" out of an iteration, and go back up top for the next round in a loop?
Both answers by the way are fine; it's just that I thought for sure that there would be a way to do this, ie some kind of an 'exit r' or some such thingy...
;-)
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 11:01 AM
#13
I guess you could also increment r
r = r + 1
Should work too.
-
Sep 17th, 2004, 11:03 AM
#14
Thread Starter
Addicted Member
Thanks....
thanks fellas....
;-)
Jim
Jim Rudnick
MCSD
KKT INTERACTIVE
www.kkti.com
-
Sep 17th, 2004, 03:56 PM
#15
you can use EXIT FOR and EXIT IF
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
|