Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows API timer(Chip Pearson) 1

Status
Not open for further replies.

WaterSprite

Technical User
Mar 23, 2004
69
US
This Windows API timer code from Chip Pearson's site works really well for me. I have two spreadsheets that need to run once each hour. I put the code in one sheet, the "parent", so to speak. So I am controlling run times for the "parent" spreadsheet and another spreadsheet using Macro's in the timerproc block of code in the parent.

Now to my question. I need to run another spreadsheet, on the same computer but this one needs to run every 15 minutes. I think that with the delclarations being public, or global, I cannot just add another spreadsheet with the timer code set at 900 seconds, seems as if the 3600 second timerproc and the 900 second timerproc would not get along. I would assume I need to change the names, such as timerproc1, etc. But, I do not know what all to change to a different name, especially if I have to change names in the Public declarations portion.

The code below is as I am currently using it, 3600 in the timer seconds and two macros being ran from the timerproc block of code.

Thanks for your help.


'
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

Sub StartTimer()
TimerSeconds = 3600 ' how often to "pop" the timer.
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
' macro10
' macro11




'
End Sub


 
One way is to set TimerSeconds to 900 and use a static variable:
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
Static i As Integer
i = i + 1
If i = 4 Then
' macro10
' macro11
i = 0
End If
' new macro
End Sub


'
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top