Results 1 to 8 of 8

Thread: Alright Dudes: how to use DoEvents?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Northern Irelans
    Posts
    17

    Arrow Alright Dudes: how to use DoEvents?

    You all mentioned I should use DoEvents, but what I could really do with is an example of how to implement this because - you guessed it - I am that complete VB 6.0 newbie which gets on everybody's nerves...


    Thanks!

  2. #2
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    Private Sub Form_Load()
    Dim x As Integer
    DoEvents
    For x = 1 To 10000
    progrsssbar = progressbar + 1 'or something like that
    Next
    'because of the doevents it will still refresh the prograss bar and you'll be able to see the changes
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Northern Irelans
    Posts
    17

    Thanks!

    Thanks Olly!

  4. #4
    AIS_DK
    Guest
    Thats not entirely true.

    If you use the supplied code, you will only clear the message stack once. If you are going to use it, it should be:

    Code:
    Private Sub Form_Load() 
    Dim x As Integer 
    
    For x = 1 To 10000 
        progrsssbar.value = progressbar.value + 1 'or something like that 
        DoEvents 
    Next  x
    End Sub
    That way you will see all updates.

  5. #5
    Registered User Olly's Avatar
    Join Date
    Apr 2001
    Location
    Switzerland
    Posts
    252
    yeah, i think so as well, but... long ago, u know not entirely sure

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Inside as you want to check for messages between each loop
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    wossname
    Guest
    Code:
    Private Sub Form_Load() 
    Dim x As Integer 
    
    For x = 1 To 10000 
        progrsssbar.value = progressbar.value + 1 'or something like that 
        DoEvents 
    Next  x
    End Sub
    This code will bring your computer to a crawl (well, not quite) because doevents lets all outstanding events happen. If you must use it in a loop then let it fire once every few hundred cycles of the loop by using a MOD statement...

    Code:
    Private Sub Form_Load() 
    Dim x As Integer 
    
    For x = 1 To 10000 
        progrsssbar.value = progressbar.value + 1 'or something like that 
        If (x mod 200) = 0 Then DoEvents 'if x is a multiple of 200
    Next  x
    End Sub
    this will let your code do rapid bursts of work and then check for events, and then another rapid burst etc...

    A simple optimising trick that will make your program run faster and be a more friendly windows citizen

  8. #8
    Megatron
    Guest
    Basically, it stops your App from freezing, because it processes other tasks.

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