Solved

time delay function

Posted on 2003-12-02
4
4,580 Views
Last Modified: 2013-12-25
Hi,

Using VB6 and i want to wait 1 second between each iteration of a do loop. What function will allow me to implement such a delay

Thanks.
0
Comment
Question by:sheslop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9863803
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 9863826
The Sleep() API will delay for the specified time but completely suspends execution of your application making it unresponsive.  (Not that this is always a bad thing...)

If you need your application to remain responsive during the delay then you can do it this way:

Private Sub delay(seconds As Long)
    Dim endTime As Date
   
    endTime = DateAdd("s", seconds, Now())
    Do While Now() < endTime
        DoEvents
    Loop
End Sub

delay 1 ' delay for one second
delay 60 ' delay for one minute

Idle_Mind
0
 

Expert Comment

by:yahayas
ID: 10409046
idle_mind,
  I will ike you to send me the code necessary to delay the system clock for say : it count's four  seconds forward then two seconds backwards,thanks.
yahayas.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 10412423
yahayas,

The code I wrote doesn't change the system clock in any way.  It simply causes the code to stay in the Do...While loop until the specified number of seconds has passed by.

What is it your trying to accomplish?

Idle_Mind
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question