|
-
Jul 27th, 2000, 05:13 AM
#1
Thread Starter
Lively Member
I don't understand why one would use the DoEvents function.
How does it affect the application?
Thanks.
Dan.
-
Jul 27th, 2000, 05:15 AM
#2
Fanatic Member
DoEvents lets the OS 'work' for a fraction of a second before returning to the procedure.
-
Jul 27th, 2000, 08:47 AM
#3
Fanatic Member
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!]
-
Jul 27th, 2000, 05:08 PM
#4
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
-
Jul 27th, 2000, 05:18 PM
#5
transcendental analytic
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.
-
Jul 27th, 2000, 05:20 PM
#6
DoEvents can prevent the OS from freezing by allowing it to process other events in it's queue
-
Jul 27th, 2000, 08:05 PM
#7
transcendental analytic
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.
-
Jul 27th, 2000, 08:08 PM
#8
Fanatic Member
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
-
Jul 27th, 2000, 08:16 PM
#9
Frenzied Member
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.
-
Jul 27th, 2000, 08:25 PM
#10
Fanatic Member
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
-
Jul 27th, 2000, 08:30 PM
#11
transcendental analytic
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.
-
Jul 27th, 2000, 08:33 PM
#12
Frenzied Member
not really, it screws up unloading the form.
-
Jul 27th, 2000, 10:05 PM
#13
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?
-
Jul 28th, 2000, 12:28 PM
#14
transcendental analytic
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.
-
Jul 28th, 2000, 12:39 PM
#15
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.
-
Jul 28th, 2000, 12:56 PM
#16
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|