Solved

time delay function

Posted on 2003-12-02
4
4,576 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
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9863803
0
 
LVL 85

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 85

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 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