ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Do While Loop using time as the counter (https://www.excelbanter.com/excel-programming/373765-do-while-loop-using-time-counter.html)

asmenut

Do While Loop using time as the counter
 
I have a datalogger that I created a few years ago. I have been asked to
create a modified logger that will log the data (when the criteria is true)
every 1 second for 10 seconds. In which case the counter will reset.

How can I code the Do WHile loop to syncronize to seconds?

Tom Ogilvy

Do While Loop using time as the counter
 
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




"asmenut" wrote:

I have a datalogger that I created a few years ago. I have been asked to
create a modified logger that will log the data (when the criteria is true)
every 1 second for 10 seconds. In which case the counter will reset.

How can I code the Do WHile loop to syncronize to seconds?


asmenut

Do While Loop using time as the counter
 
Thanks Tom

"Tom Ogilvy" wrote:

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




"asmenut" wrote:

I have a datalogger that I created a few years ago. I have been asked to
create a modified logger that will log the data (when the criteria is true)
every 1 second for 10 seconds. In which case the counter will reset.

How can I code the Do WHile loop to syncronize to seconds?



All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com