Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VB - Manually stop a do while loop

  • 13-07-2008 08:30PM
    #1
    Registered Users, Registered Users 2 Posts: 938 ✭✭✭


    Wonder if anyone can help me with this, I need to try and stop a do while loop manually, I have one button to start the loop and another to stop it. I have tried this

    Do while button_Start.enabled = false
    .....
    Loop

    In the stop button event I have set button_start.enabled = True but
    this just causes the application to stop responding and doesn't exit.


Comments

  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    This isn't VB specific, but could you not make the while not true?

    e.g.

    Do {

    whatever

    } while(x>0)

    Just make x equal 0 or less than 0.


  • Registered Users, Registered Users 2 Posts: 5,238 ✭✭✭humbert


    While not button.enabled
    ...
    end while

    should be working, sure the code isn't getting suck somewhere inside the loop?


  • Registered Users, Registered Users 2 Posts: 2,157 ✭✭✭dazberry


    The stop button event isn't firing because the message loop isn't being processed because you're locked into the while loop (remember that Win32 GUI is single threaded). VB has something like a DoEvents call (in Delphi its Application.ProcessMessages) - if you put this in your while loop your stop button event should then fire.

    D.


  • Registered Users, Registered Users 2 Posts: 5,238 ✭✭✭humbert


    Ah, good call. Should have spotted that!


  • Registered Users, Registered Users 2 Posts: 938 ✭✭✭logic


    Thanks Dazberry, that done the trick. I had seen do events before in some one elses code but didn't understand what it did.


  • Advertisement
Advertisement