Results 1 to 9 of 9

Thread: [RESOLVED] Getting out of a For Next Loop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    100

    Resolved [RESOLVED] Getting out of a For Next Loop

    Hi

    I am still learning and apologize for insulting anyones intelligence...

    How do you get out of a For/Next loop with

    If x=y then (get out of loop)

    Suffering brain fog at the moment

    Thanks

    Mike

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Getting out of a For Next Loop

    VB Code:
    1. If x = y Then
    2.      Exit For

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    100

    Re: Getting out of a For Next Loop

    Quote Originally Posted by Hack
    VB Code:
    1. If x = y Then
    2.      Exit For

    Thanks

    However I get "Next without for Error"

    VB Code:
    1. For z = 0 To 19
    2.    If (a + z + 1) > 20 Then
    3.    Exit For
    4.    
    5.    
    6.     If Abs(Text2(0 + z).Text - Text2(a + z + 1).Text) <= y Then w = w + 1
    7.    
    8.  
    9.   Next z

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Getting out of a For Next Loop

    Quote Originally Posted by leachim
    Thanks

    However I get "Next without for Error"

    VB Code:
    1. For z = 0 To 19
    2.    If (a + z + 1) > 20 Then
    3.    Exit For
    4.    
    5.    
    6.     If Abs(Text2(0 + z).Text - Text2(a + z + 1).Text) <= y Then w = w + 1
    7.    
    8.  
    9.   Next z
    That makes sense. You need to add an End If after your Exit For.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    100

    Re: Getting out of a For Next Loop

    Yep

    Works

    It also works without the End If if you have "Then Exit For" on the same line.

    I have the "Idiots Guide to VB 6" - although Seem to learn better from Video or DVD - Is there such a resource ?

    The Idiots Guide doesn't tell me what I have just learnt - Can you recommend a book/video that is easy to learn from

    Thanks Again

    Mike

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Getting out of a For Next Loop

    Quote Originally Posted by leachim
    Yep

    Works

    It also works without the End If if you have "Then Exit For" on the same line.

    I have the "Idiots Guide to VB 6" - although Seem to learn better from Video or DVD - Is there such a resource ?

    The Idiots Guide doesn't tell me what I have just learnt - Can you recommend a book/video that is easy to learn from

    Thanks Again

    Mike
    This is my Bible!!!!!!!!

    See if you can get a used copy (I believe it is out of print).

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Getting out of a For Next Loop

    My Bible is Tricks of the 3D Game Programming Gurus.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    100

    Re: Getting out of a For Next Loop

    Just ordered one for $11 inc delivery to UK !!

    Forgot to ask what they were new !!

    1 drawback is that it was written for VB 5 ?

    Mike

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Getting out of a For Next Loop

    Quote Originally Posted by leachim
    Just ordered one for $11 inc delivery to UK !!

    Forgot to ask what they were new !!

    1 drawback is that it was written for VB 5 ?

    Mike
    I've had it for years and years and still refer to it occassionally.

    There are features of VB6 not found in VB5, that is true, however, it will cover the vast majority of things that you will be interested in learning.

    Also, take a look as some of these links. I have no idea what is good or bad, but some of the titles sound like something you would be interested in.

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