View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kragelund Kragelund is offline
external usenet poster
 
Posts: 34
Default Tom Ogilvy - Timer help

Tom, you posted this brilliant piece of code (below) in a response to a
question with the title " Do while loop using time as the counter". I found
it (potentially) extremely useful and intricate. So much so that I don't know
how to adapt it to my own purpose, which is to initiate a validation
procedure on a sheet at user given intervals, for instance every two minutes.
Can you (or somebody equally gifted) explain how I modify the code to loop
every e.g. 120 seconds until the user specifically orders the procedure to
stop?

Your help would be greatly appreciated!

Henrik



Public Declare Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, ByVal nidevent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, ByVal nidevent As Long) As Long

Public timerid As Long
Public timerseconds As Single
Public Cnt As Long

Sub StartTimer()
timerseconds = 1 'how often to "pop"the timer
Cnt = 0
timerid = SetTimer(0&, 0&, timerseconds * 1000&, _
AddressOf Timerproc)
End Sub

Sub endtimer()
On Error Resume Next
KillTimer 0&, timerid
End Sub

Sub Timerproc(ByVal hwnd As Long, ByVal umsg As Long, _
ByVal nidevent As Long, ByVal dwtimer As Long)
Range("A1").Value = Cnt + 1
Beep
Cnt = Cnt + 1
If Cnt < 10 Then Exit Sub

endtimer
End Sub

write your log in the timerproc
--
Regards,
Tom Ogilvy