| Timer |
| |
| |
| Store the next event time in a variable. use a timer to check periodically to see if the time has arrived. |
| Private Const INTERVAL_SECONDS = 20 * 60 | |
| Private NextEventTime As Single | |
| |
| Private Sub StartTimer() | |
| NextEventTime = Timer + INTERVAL_SECONDS | |
| If NextEventTime - Timer < 60000 Then |
| tmrTrigger.Interval = (NextEventTime - Timer) * 10 |
| Else |
| tmrTrigger.Interval = 60000 | |
| End If | |
| tmrTrigger.Enabled = True | |
| End Sub | |
| |
| Private Sub Form_Load() | |
| StartTimer | |
| lblEventTime.Caption = Format$(DateAdd("s", INTERVAL_SECONDS, Time)) |
| End Sub | |
| |
| Private Sub tmrTrigger_Timer() | |
| If Timer >= NextEventTime Then | See if it time for the event. |
| lblEventTime.Caption = Format$(DateAdd("s", _ | Process the event. |
| INTERVAL_SECONDS, Time)) | |
| NextEventTime = NextEventTime + INTERVAL_SECONDS | Set the new event time. |
| End If | |
| If NextEventTime - Timer < 60 Then | Set the timers interval. |
| tmrTrigger.Interval = (NextEventTime - Timer) * 10 | |
| Else | |
| tmrTrigger.Interval = 60000 | |
| End If | |
| End Sub | |
| |