exit for next loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    exit for next loop

    i am using vb6
    i had make a for next loop which fill data into
    the table
    now , some time it may needed that we want to
    cancel that loop .
    now what is the code to exit the for next loop

    i want it like that it the user click on the button
    the loop will exit
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    sorry, just realised you are using VB 6 and my last reply was for vb .net but what about declaring a boolean value and using do until boolean=false

    ie

    Code:
    do until filltext  = false 
    
    number=number +1
    label1.text=number
    
    loop
    then for the button you can have it set the boolean as false

    again I have only just started using VB so others may have a better answer

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #3
      if you are using a for loop you could do this as -

      Code:
          For n = 1 To 10
                  If exitfill = true Then Exit For
          Next

      Comment

      • muddasirmunir
        Contributor
        • Jan 2007
        • 284

        #4
        is this possible that on pressing Esc button we exit from loop;
        creating button and clicking it is creating problem as when if the loop
        started it is not possible to click any button

        Comment

        • jg007
          Contributor
          • Mar 2008
          • 283

          #5
          I don't know a lot about threading but with what I know it sounds like your best option is using a multithreaded program

          I have some code but as i don't know a lot about threading and and I cant advise fullt on how to access one thread from another which my code doesn't do somebody else might be better to advise.

          Comment

          • !NoItAll
            Contributor
            • May 2006
            • 297

            #6
            VB6 Code

            For I = 0 to 365

            DoEvents 'you should normally call this in any tight loop
            If bEscapePressed = true then
            Exit For
            End if

            'do all your other things here

            Next I

            bEscapePressed needs to be global.
            Set the forms keypreview property to true and if the keydown event (in the same form) is the Esc Key you can set the boolean bEscapePressed to True.


            Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)

            If KeyCode = 27 Then
            bEscapePressed = True
            End If

            End sub

            This will not work unless you have the DoEvents in the for loop. No need for multithreading - that's like hiring Picasso to paint your deck.

            Comment

            • jg007
              Contributor
              • Mar 2008
              • 283

              #7
              Originally posted by !NoItAll
              This will not work unless you have the DoEvents in the for loop. No need for multithreading - that's like hiring Picasso to paint your deck.
              Thanks the slightly better sugestion !, I am fairly new to VB so the threading was the only thing that came to mind :D.

              always plenty to learn !

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by jg007
                always plenty to learn !
                Ain't that the truth! :)

                Don't be put off - we need more people to get involved. Thanks for making the effort. (Wish I knew more about threads.)

                Comment

                Working...