Solved

time delay function

Posted on 2003-12-02
4
4,572 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 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now