Solved

time delay function

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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