Results 1 to 15 of 15

Thread: For...Next jump syntax?(RESOLVED)

  1. #1

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    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

  2. #2
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    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

  3. #3

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    ?????????

    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

  4. #4
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    Sorry but what i said about IF staments in For..Next still stands take a look at the following

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim x As Integer
    5.  
    6.     For x = 1 To 100
    7.  
    8.         If x < 10 Then
    9.             Debug.Print x
    10.         Else
    11.             x = 100
    12.         End If
    13.  
    14.     Next
    15. End Sub

    Hope this helped!!

  5. #5

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    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

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Code:
    For i = 1 to 50
       If somthing > 0 Then
           Goto myLabel
       End If
    
       ' Other code you need to skip
    
    myLabel:
    Next i
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    It seems a simple If Else would work.

    VB Code:
    1. For i = 1 to 85
    2.  
    3.    'code snip
    4.    If FOUNDIT > 0 Then        
    5.       Text14.Text = FOUNDIT
    6.       ' found transparent so jump to next iteration
    7.    Else
    8.       'code snip here where I parse the string and then save it in a list
    9.    End If
    10.  
    11. Next

  8. #8

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    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

  9. #9
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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 = ""
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  10. #10

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    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

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    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

  13. #13
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I guess you could also increment r

    r = r + 1

    Should work too.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  14. #14

    Thread Starter
    Addicted Member JVRudnick's Avatar
    Join Date
    Oct 2001
    Location
    Toronto, Canada
    Posts
    135

    Thanks....

    thanks fellas....

    ;-)

    Jim
    Jim Rudnick
    MCSD
    KKT INTERACTIVE
    www.kkti.com

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    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
  •  



Click Here to Expand Forum to Full Width