Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Creating Long Delays

I've been trying to create a simulator - it requires as close to real-time operation as possible. I have a couple of questions about timers.
  1. How do I activate a timer for more then 60 seconds?
  2. Will DoEvents be good enough to make sure all the other procedures are working? There could be more then one "delayed" record in one time. Help will be highly appreciated!

    To create a timer that lasts 60 seconds, in the Timer_Timer event, keep a counter of how many 60 second intervals have taken place. Once the counter reaches 5, for instance, do your regular code. That would let you time a five minute interval, for instance. Make sure you reset the counter when you reach the intended count.

    DoEvents tells VB to process the event queue. Make sure you have them in any long-running loops. If you're using a timer, VB considers that code idle and can process other code at the same time. DoEvents is useful if you are using a busy loop or are processing lots of records in a loop. A DoEvents in between will let the interface refresh occasionally. Supposedly, VB 4.0 and Windows 95 don't need the DoEvents; however, I have found that without them, the user interface does not refresh at all in some cases.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date