SysTime is a small library to get and set the current system time and system date.
There are two different dll's, one for the desktop and one for the device.
Thanks to your DLL, I can set the clock with GPS date and time.
Here is the source for everybody. Perhaps someone can shorten it
Code:
'Requires Registry DLL (object reg), Bitwise DLL (object bit) and Filippo's SysTime DLL (object SysTime) Sub Globals Dim zti(0) AsByte'binary array for GetTimeZone End Sub
Sub App_Start Reg.New1 SysTime.New1 End Sub
Sub mnuSetSystemDateTime_Click IfGPS.Status<>"A"ThenReturn'Aborts if no stable GPS signal present 'GPS.UTCDate and GPS.UTCTime available from Sub GPS_GPSDecoded. Please see gps.dll Help for details Dim x, y, i, zt zt = GetTimeZone x = DateParse(GPS2Date(GPS.UTCDate)) y = TimeParse(GPS2Time(GPS.UTCTime)) + zt/24 * cTicksPerDay 'add your local time zone i = Msgbox("GPS date and time converted to local is " & CrLf & Date(x) & "" & Time(y) & CrLf & "Set the device?"," Confirmation",cMsgBoxYesNo,cMsgBoxQuestion) If i = cNo ThenReturn ErrorLabel(SetError) 'There is no success flag in the SysTime DLL SysTime.New1 Systime.SetDate(DateMonth(x),DateDay(x),DateYear(x)) Systime.SetTime(TimeHour(y),TimeMinute(y),TimeSecond(y)) Msgbox("GPS Date and Time set."," GPS Date and Time",cMsgBoxNone,cMsgBoxAsterisk) Return SetError: Msgbox("Error setting Date and Time."," GPS Date and Time",cMsgBoxNone,cMsgBoxHand) End Sub
Sub GPS2Time(x) Dim colon TimeFormat("HH:mm:ss") colon=SubString(x,0,6) colon=StrInsert(colon,2,":") colon=StrInsert(colon,5,":") x = TimeParse(colon) if chkAMPM.Checked=TrueThen TimeFormat("hh:mm:ss tt") 'A check box selects EU or US format Return Time(x) End Sub
Sub GPS2Date(x) Dim dash DateFormat ("yyyy/mm/dd") dash="20" & SubString(x,4,2) & "/" dash=dash & SubString(x,2,2) & "/" dash=dash & SubString(x,0,2) x = DateParse(dash) if chkAMPM.Checked=falsethen'A check box selects EU or US format DateFormat("dd/mm/yyyy") else DateFormat("mm/dd/yyyy") Endif Return Date(x) End Sub
Sub GetTimeZone Dim m, i, b Reg.RootKey(Reg.rtLocalMachine) If cPPC = TrueThen zti()=Reg.GetValue("Time","TimeZoneInformation") For i = 3To0Step -1 m = m & bit.DecToHex(zti(i)) Next m = bit.HexToDec(m) / 60 * (-1) Else m = Reg.GetValue("System\CurrentControlSet\Control\TimeZoneInformation","ActiveTimeBias") m = m / 60 * (-1) EndIf If m > 0Then m = "+" & m Return m End Sub
Sorry gents,
There is an error in
mnuSetSystemDateTime_Click
which I have corrected as:
Code:
Sub mnuSetSystemDateTime_Click IfGPS.Status="A"Then Dim x, i x =DateParse(GPS2Time(GPS.UTCTime)) 'addition of time zone must account for date change x = x - x Mod cTicksPerDay x = x + TimeParse(GPS2Time(GPS.UTCTime)) + zt * cTicksPerHour i = Msgbox("GPS date and time converted to local is " & CrLf & Date(x) & "" & Time(x) & CrLF & "Set the device?"," Confirmation",cMsgBoxYesNo,cMsgBoxQuestion) If i = cNo ThenReturn ErrorLabel(SetError) SysTime.New1 Systime.SetDate(DateMonth(x),DateDay(x),DateYear(x)) Systime.SetTime(TimeHour(x),TimeMinute(x),TimeSecond(x)) Msgbox("GPS Date and Time set."," GPS Date and Time",cMsgBoxNone,cMsgBoxAsterisk) Return SetError: Msgbox("Error setting Date and Time."," GPS Date and Time",cMsgBoxNone,cMsgBoxHand) Else Msgbox("GPS data unstable or not available."," GPS Status",cMsgBoxNone,cMsgBoxHand) Return EndIf End Sub
Sub mnuSetSystemDateTime_Click ... i = Msgbox("GPS date and time converted to local is " & CrLf & Date(x) & "" & Time(x) & CrLF & "Set the device?"," Confirmation",cMsgBoxYesNo,cMsgBoxQuestion) ... Return nd Sub
It's not ideal to ask the user a question and then set the time to what was determined before asking the question.
In a Psion program that I wrote years ago to do this I showed the disparity when asking the question (as well as GPS and system times) and then if the user requested time alteration I adjusted the system time by the disparity amount. This is then independent of the user's decision time...
SysTime is a small library to get and set the current system time and system date.
There are two different dll's, one for the desktop and one for the device.
Ciao.
Filippo
This looks jolly useful (surprising it is not already included in other libraries!).
But when I add the DLLs I get offered objects of type "SysTime" (as I expected) but also "SYSTEMTIME". What is the difference, please (and how to remember the distinction; it's not in the Help!).
Thanks to your DLL, I can set the clock with GPS date and time.
Here is the source for everybody. Perhaps someone can shorten it
Code:
...
Sub GetTimeZone Dim m, i, b Reg.RootKey(Reg.rtLocalMachine) If cPPC = TrueThen zti()=Reg.GetValue("Time","TimeZoneInformation") For i = 3To0Step -1 m = m & bit.DecToHex(zti(i)) Next m = bit.HexToDec(m) / 60 * (-1) Else m = Reg.GetValue("System\CurrentControlSet\Control\TimeZoneInformation","ActiveTimeBias") m = m / 60 * (-1) EndIf If m > 0Then m = "+" & m Return m End Sub
I guess all that stuff with DecToHex and HexToDec is just to convert 4 bytes to a 32-bit integer. Which could be done with some *256 or neatly with the ByteConverter DLL using Int32FromBytes().
But reading the registry item separately on my PDA gives four zeroes (but lots of other following bytes; goodness knows what they mean!). This is fair enough since I am in Zulu time zone. But I am also in daylight saving time, so where would that other hour correction come from?
lots of other following bytes; goodness knows what they mean!
I suspect they contain the DST information for the time zone.
Quote:
SYSTEMTIME
That is a struct definition that shouldn't really be visible. An instance of it is passed to the OS to set or get the time and date information. It is of no use as a Basic4ppc object.
@Filippo - how about hiding "SYSTEMTIME" by renaming it "_SYSTEMTIME" and providing the sources for merging?
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.