Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I just want to set up a Do-Loop that exits after a certain number of seconds
have elapsed. The following code does not work, but I think you will get the idea. This does not need to be that precise, just approximate. Could someone please correct my code to work or post some other example code that does run? Something like: Dim dTimeBeg as Date Dim dTimeEnd as Date Dim lElapsed as Long lElapsedSeconds = 49 <<<<<<<<<this would be seconds I specify dTimeBeg = Now() Do dTimeEnd = Now() If dTimeEnd = dTimeBeg + lElapsedSeconds then Exit Do Loop Thanks much in advance. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This is not a loop, but I assume you're just wanting to have some kind of
delay before executing the next line of code after the loop. If so, then you might find this useful: Sub Test() Dim waitTime As Date MsgBox "Hello, World" waitTime = TimeSerial(Hour(Now), Minute(Now), Second(Now) + 1) Application.Wait waitTime MsgBox "One Second has elapsed" End Sub -- Hope that helps. Vergel Adriano "XP" wrote: I just want to set up a Do-Loop that exits after a certain number of seconds have elapsed. The following code does not work, but I think you will get the idea. This does not need to be that precise, just approximate. Could someone please correct my code to work or post some other example code that does run? Something like: Dim dTimeBeg as Date Dim dTimeEnd as Date Dim lElapsed as Long lElapsedSeconds = 49 <<<<<<<<<this would be seconds I specify dTimeBeg = Now() Do dTimeEnd = Now() If dTimeEnd = dTimeBeg + lElapsedSeconds then Exit Do Loop Thanks much in advance. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just in case you wanted to do something in your Do loop (so that the
excellent Wait() suggestion won't work...): Const nSeconds as Long = 49 Dim dTimeEnd As Double dTimeEnd = Now + TimeSerial(0, 0, nSeconds) Do Loop Until Now = dTimeEnd In article , XP wrote: I just want to set up a Do-Loop that exits after a certain number of seconds have elapsed. The following code does not work, but I think you will get the idea. This does not need to be that precise, just approximate. Could someone please correct my code to work or post some other example code that does run? Something like: Dim dTimeBeg as Date Dim dTimeEnd as Date Dim lElapsed as Long lElapsedSeconds = 49 <<<<<<<<<this would be seconds I specify dTimeBeg = Now() Do dTimeEnd = Now() If dTimeEnd = dTimeBeg + lElapsedSeconds then Exit Do Loop Thanks much in advance. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Exit to the beginning of For Next loop | Excel Discussion (Misc queries) | |||
exit for next loop | Excel Programming | |||
Looping procedure calls userform; how to exit loop (via userform button)? | Excel Programming | |||
exit from a loop? | Excel Programming | |||
exit from a loop? | Excel Programming |