Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Loop for X seconds then exit

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Loop for X seconds then exit

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Loop for X seconds then exit

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit to the beginning of For Next loop CousinExcel Excel Discussion (Misc queries) 3 May 13th 10 01:03 PM
exit for next loop David Henderson Excel Programming 2 March 23rd 06 08:07 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
exit from a loop? Kieran1028[_5_] Excel Programming 0 November 10th 04 02:55 PM
exit from a loop? crispbd[_23_] Excel Programming 0 November 8th 04 09:22 PM


All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"