Be aware that all the code posted in this thread has a downside. Even the Sleep API posted by Mark, who I have the utmost respect for. The Sleep API is fine if you don't want anything else in your app to be processed during the Sleep period. During the Sleep period your entire app... code....CommandButtons ...Timers .. everything is in a comatose state. Set Sleep for Sleep 10000 and try to click a CommandButton. The rest of the examples won't have that problem but will suck up processor cycles like a Black Hole. Open up your Task Manager and go to the Performance tab (XP) or System Tools (Resource Meter) in W98. Then run anyone of the other postings with the Pause or Delay period of 10 seconds and watch the resource meter. This code is the best of both worlds, as it combines the Sleep API with a Pause Sub. Since the Sleep value is held constant @ 1mS * 2 (called twice) it won't freeze your app, even with a very long Pause value. This code won't suck your processor dry either! 'http://www.martin2k.co.uk/forums/index.php?s=b53bcad9aa27dd0bd8f62236ce4f9548&showtopic=4767&st=0&#entry66501 'beatle ' date='Jul 18 2008, 12:24 PM' post='66518'] The "By Wayne" comment would 'suggest so. Your not handling the possibility of an over midnight pause, which 'although rare would put it in an infinite loop. You could also use Sleep API to 'save hammering the cpu. 'Notes: This modified Pause Sub by Beatle doesn't eat CPU cycles!!!!
Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Credits: (Beatle aka Milk (Sleep+Pause Sub)). (Wayne Spangler (Pause Sub)) Private Sub Pause(ByVal Delay As Single) Delay = Timer + Delay If Delay > 86400 Then 'more than number of seconds in a day Delay = Delay - 86400 Do DoEvents ' to process events. Sleep 1 ' to not eat cpu Loop Until Timer < 1 End If Do DoEvents ' to process events. Sleep 1 ' to not eat cpu Loop While Delay > Timer End Sub
Private Sub Form_Load() Form1.Show Pause 10 Form1.Caption = "Pause has timed out!" End Sub
Sexy code formating by Mark's 'SyntaxHighlighter'
________________________________________________________________ "So much to learn. So little time to do it. Wise men know it's later than one thinks"! Mark's Syntax.Zip Pause Sub I don't answer programming questions via PMs. That's what the forum is for!
|