Results 1 to 16 of 16

Thread: DoEvents

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    u.s.a
    Posts
    127
    I don't understand why one would use the DoEvents function.
    How does it affect the application?

    Thanks.
    Dan.

  2. #2
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    DoEvents lets the OS 'work' for a fraction of a second before returning to the procedure.
    Courgettes.

  3. #3
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    I use it all the time

    Lets say you have a long process that needs to run but your program is also monitoring a COMM port for incomming data, with out a doevents it the process loop (or multithreading the app) the incomming data will never be detected





    Kurt Simons
    [I know I'm a hack but my clients don't!]

  4. #4
    Guest
    It is also good for a stop button or anything to stop a certain sub or function.

    Code:
    Private Sub cmdstop_Click()
    Do
    DoEvents
    Loop
    End Sub

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Doevents will allow YOUR applications events to get fired.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Guest
    DoEvents can prevent the OS from freezing by allowing it to process other events in it's queue

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Don't be so sure on that, Sam told me that it only concerns your applications events
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Originally posted by Matthew Gates
    It is also good for a stop button or anything to stop a certain sub or function.

    Code:
    Private Sub cmdstop_Click()
    Do
    DoEvents
    Loop
    End Sub
    This is a good skeleton to understand DOEVENTS.
    Chemically Formulated As:
    Dr. Nitro

  9. #9
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    try something like this
    Code:
    Private Sub Command1_Click()
    Dim x As Long
    x = Timer
    Do Until Timer > (x + 10)
    
    Loop
    
    MsgBox "Hello"
    End Sub
    Your App and the IDE will freeze for 10 seconds, but other processes will continue to function as normal. (unless you've been messin with thread priorities) All doevents does is check your own threads message queue and process any events such as command clicks, repainting and moving etc. without doevents your App apears to be frozen, but other processes keep going.

  10. #10
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Hello Sam


    Danab, start a new project and drop a command button on the form.
    Code:
    Option Explicit
    Private b_Cancel As Boolean
    
    Private Sub Command1_Click()
      b_Cancel = True
    End Sub
    
    Private Sub Form_Click()
      b_Cancel = False
      Do While Not b_Cancel
        Me.BackColor = QBColor(Rnd * 10)
        DoEvents
      Loop
    End Sub
    Run the program. Click on the form and when you want to stop click on the command button.

    [Edited by Nitro on 07-27-2000 at 09:31 PM]
    Chemically Formulated As:
    Dr. Nitro

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Good programming habit

    Hmm, what do you think guys? Isn't this a good progamming habit?
    Code:
    Do
      'Code
      doevents
    Loop While Forms.count
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    not really, it screws up unloading the form.

  13. #13
    Guest
    Originally posted by Nitro

    This is a good skeleton to understand DOEVENTS.
    What do you mean "skeleton"?

    But actually, I like it because, well...explanation:

    Code:
    Do 'Do the process
    DoEvents 'Just do nothing
    Loop 'Loop it
    So making it as a stop button will stop any events that are happening because it is doing the current code, but there is nothing to do actually so it just hangs there . Get what I mean?

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    not really, it screws up unloading the form.
    You didn't mean me right?= because it should prevent screwing up when unloading all forms
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15
    Guest
    Matthew. DoEvents may seem like it does nothing, but in reality, it pauses execution for a fraction of a second so the OS can process other tasks.

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    IN reality Doevents allows YOUR events to get fired, not allowing Other tasks getting processed, and that fraction of a second depends on what event's you get fired
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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