Re: Timer interval limitation

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 02/27/04


Date: Fri, 27 Feb 2004 10:35:49 -0500


> IF both are recorded and 'full date' VB routines are used. Unfortunately
> that 'if' is often not taken into consideration. Any routine that is
> expected to work pass midnight should be tested for 'midnight' - if OK,
then
> fine, no additional code is needed.
>
> The programmer that doesn't validate for midnight for his particular timer
> does so at his (or rather his client's) perl.

You are setting an "interval" timer, not an alarm clock. Simply set the
ending time as the amount of time past Now. There are several ways to
approach that. Here's one way where a CommandButton is used to start a 15
minute timer (as was the OP's original request). Note that it will work
across midnight with no trouble.

Rick - MVP

Dim TimeIsUp As Date

Private Sub Command1_Click()
  ' Start the timer for 15 minutes
  TimeIsUp = DateAdd("n", 15, Now)
  Timer1.Interval = 250
  Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
  If Now >= TimeIsUp Then
    ' Code to "Sound the Alarm"
    Timer1.Enabled = False
  End If
End Sub


Quantcast