devxlogo

Creating Long Delays

Creating Long Delays

Question:
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 proceduresare working? There could be more then one “delayed” record in one time.Help will be highly appreciated!

    Answer:
    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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist