Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4589
  • Last Modified:

time delay function

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
sheslop
Asked:
sheslop
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
yahayasCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now