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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Time Change 1

Status
Not open for further replies.

TheVampire

Programmer
May 1, 2002
828
0
0
US
Is there a way to have an event fire in a program if the user manually changes the PC clock setting, or if another program changes the clock in code?

I know there is a way to detect some system changes ( like screen resolution ), but does this library include changing the time?

Robert
 
If it helps, there is a variable "Time" that automatically holds your system clock's time.

There are some more, but I forgot what they are. The only other one I can remember is "Timer", it holds the number of seconds since midnight.
 
Depends if the System Info control is good enough for the purpose or not (it has events to capture things like this), or if you want to go the API route.
 
CCLINT:

I'll try the sys info control and see if it works or not. I just couldn't remember which control it was that did this...

Robert
 
Hows this:

Dim LTime as Long

Private Function CheckTimeChange() as Boolean
If LTime <> Now() then
CheckTimeChange = False
else
CheckTimeChange = true
end if
LTime = Now()
End Function


Brett
 
Brett:

That's not an event, that's polling. I want a solution that is event driven.

Thanks anyways,

Robert
 
I think it will almost always return FALSE
(I beleive that this is what you meant anyways)

unless you change:

Dim LTime as Long
to
Dim LTime as Single

Or:
If LTime <> Now() then
to
If LTime <> CLng(Now()) then

Then it will almost always return TRUE.

If you leave it &quot;As-Is&quot; it will return True only once a day, and that only if the program is left running over midnight.


 

I know what you mean. You'll get me next time...
 
Update:

The sysinfo control will work OK if the time or date is changed directly from the windows clock / desktop. If the time change was done in code by another program, then the sysinfo did not detect it and fire an event.

Just to let you know,

Robert
 
> If the time change was done in code by another program

Yes, well if theis other program refuses to follow the rules...

OK, I'll grant that finding that there are supposed to be rules is tricky, but theoretically any program that changes the clock is supposed to send a notification message. When the OS gets that message it broadcasts the necessary system message to tell interested applications (eg the SysInfo control) that the time has changed. Of course, if the application that makes the original change doen't bother to formally tell the OS, well...the whole thing collapses...
 
OK, then I should say that it may or may not detect the time change, depending on if the other program plays well with others or not. [smile]

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top