Results 1 to 6 of 6

Thread: DoEvents

  1. #1
    Join Date
    Dec 2004
    Posts
    37

    Question Unanswered: DoEvents

    I used a piece of advice I read on here ages ago and now cannot remember how it worked. I was hoping someone could refresh my memory.

    It was to do with DoEvents.

    I have a Form with a Button that sets a piece of code running with a Progress bar that tells me how it is going.

    This code can run for anything from a few seconds to 10 minutes. The code works fine, but sometimes when I set this in motion and the progress bar lets me know that it is going to run for longer than 5 minutes I would like the option to stop the code and either change the parameters for the loop or run it at a more convenient time.

    Simply a "Halt" Button.

    Can someone refresh my memory as to how this can be done.

    Many thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    DoEvents is not used for what you need.
    You need a multi treading system which access does not have.
    You can not press another button while your code runs.
    Do you need that for testing purpose?

    Waht you can do, use the Stop statement to according to any condition i.e if the loop is being done 170 times

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    IF it can be done, you would need to have the DoEvents in your loop. Each iteration of the loop would need to test if it can continue (check a global/local scope flag). The "Halt" button would set that flag. Like Hammy said, it might not be possible once you get into the loop ... Depending on how many things happen in the loop, you might need a DoEvents after each action (to try and capture the setting of the flag) ...
    Back to Access ... ADO is not the way to go for speed ...

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    had to do this yesterday with a loop(loop(loop(loop(loop)))) sort of situation manipulating a whole bunch of memory arrays. currently researching a better algo since the current one takes me through hundreds of millions of iterations and runs for an hour or so.

    in my case all looping is in one form. form has a cancel button. cancel sets a formwide WannaExit As Boolean. at a "suitable" level in the nested loop structure, doevents and check the value of WannaExit and if set, back out gracefully from the loop nest (all higher loops test WannaExit and exit to pass control back up the chain)

    "suitable" here defined by considerations of response-time to the cancel vs slowdown while doevents cedes control.

    if you are not nested, make some sort of counter that lets you run doevents occasionally (? every 1000 cycles) rather than every cycle.

    contrary to hammbaka's suggestion, Windows was indeed queuing my cancel_click() and processing it when the doevents ocurred. this might be specific to my nested loops or might apply generally with the counter/doevents ...don't know!

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Izy ... Applies in general. It's not specific. Just another message in the Windows Message Loop that gets handed off to the appropriate process ...
    Back to Access ... ADO is not the way to go for speed ...

  6. #6
    Join Date
    Dec 2004
    Posts
    37

    Talking Got it Sorted!!

    Sorted it last night.

    Insert a global variable called 'HaltProcess". It could have been a local variable, but I use it for a number of actions, including classes that I can halt without having to have several local flags.

    Set HaltProcess false before I enter any loops

    Get the Halt button to set HaltProess to true when clicked.

    Use DoEvents and check the flag within the loops. If set true then goto a a closedown procedure that exits the procedure gracefully.

    Quite simple and elegant.

    Many thanks to all those that replied.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •