Checking for 5.30pm

J

John

Hi

How can I check in code (in UK locale) if current time is 5.30 or over ?

Thanks

Regards
 
A

Arvin Meyer [MVP]

John said:
Hi

How can I check in code (in UK locale) if current time is 5.30 or over ?

Set a form's TimerInterval to 60000 (milliseconds) which is 1 minute. Use
the following code in the form's Timer event:

Private Sub Form_Timer()
If Timer >= 63000 Then ' 5:30 PM
MsgBox "The time is now past 5:30 PM" vbOKOnly
End If
End Sub
 
B

BruceM

Wouldn't that generate a message box every 63 seconds? I'd think it would
be something like this in the Timer event (with the interval set as you
described):

If Time > #5:30:00 PM# Then
MsgBox "The time is now past 5:30 PM"
End If
 
P

Pieter Wijnen

It Will in both cases trigger about once a minute once it gets started ,-)
Arvins typo will probably mean you're long gone anyway

I'd add something like:
Private Sub Form_Timer()
static hasrun as boolean
If Now() > Date() + 63000 And Not hasrun Then ' 5:30 PM
hasrun = true
MsgBox "The time is now past 5:30 PM" vbOKOnly
End If
End Sub

Pieter
 
B

BruceM

My point was that it would trigger every five minutes no matter what time it
is. I see your point, though. It all depends on the purpose of the
advisory. If for instance the day's shipment needs to arrive at the loading
dock by 6:00, a notice every five minutes may be appropriate.

"Pieter Wijnen"
 
P

Pieter Wijnen

Note that Arvin said to set the Timer Interval to 1 Minute
63000sec = 60sec*60min*17,5hrs

PS Timer Actually Counts the number of secconds elapsed since midnight & is
thus perfectly valid (my mind was elsewhere).
Either of the Proposed checks will work (Timer probably beeing the faster as
it only involves one function call)

No harm intended

Pieter
 
B

BruceM

My mind was elsewhere too. I don't know where I came up with five minutes.
Also, I mistakenly saw the 63000 as somehow related to the 60000, rather
than with the Timer function. In short, I confused the timer event with the
timer function, with a few imaginative twists of my own.

"Pieter Wijnen"
 
A

Arvin Meyer [MVP]

The fact is, that the TimerInterval does need to be reset to avoid running
this once per minute after 5:30 PM. My original code quit the application at
5:30 so I could make sure that no one was in the database.
 
B

BruceM

I acknowledge that I was in error, for the reasons stated in another part of
the thread about scrambling the timer function and the timer interval in my
brain, and heading off on an odd tangent from there.
 
Top