I have some code, found from the net that I am trying to use to the synchronise the clock to midnight when I get an external signal.
OK
have the following setup, defined as global, so access from everywhere
Private Structure SYSTEMTIME
Dim wYear As UInt16
Dim wMonth As UInt16
Dim wDayOfWeek As UInt16
Dim wDay As UInt16
Dim wHour As UInt16
Dim wMinute As UInt16
Dim wSecond As UInt16
Dim wMilliseconds As UInt16
End Structure
Private Declare Function SetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME) As UInt32
I have a timer that processes this every 1.5 seconds that contains
Dim Midnight1 As DateTime
Dim Midnight2 As DateTime
Dim Test1 As Long, Test2 As Long
Dim timeStru As SYSTEMTIME
Followed by
If (DIOdata And DiMask2) = 0 Then
DateTimeSync = False
ElseIf Not DateTimeSync Then
Midnight1 = Format(Date.Now, "dd/MM/yyyy") + " 00:00:00"
Midnight2 = Format(Date.Now, "dd/MM/yyyy") + " 23:59:59"
Test1 = Math.Abs(DateDiff(DateInterval.Second, Now(), Midnight1))
Test2 = Math.Abs(DateDiff(DateInterval.Second, Now(), Midnight2) + 1)
If Test1 > Test2 Then
Midnight1 = DateAdd(DateInterval.Day, 1, Midnight1)
End If
timeStru.wDay = Midnight1.Day
timeStru.wMonth = Midnight1.Month
timeStru.wYear = Midnight1.Year
timeStru.wHour = 0
timeStru.wMilliseconds = 0
timeStru.wMinute = 0
timeStru.wSecond = 0
SetSystemTime(timeStru)
DateTimeSync = True
ESDsync = True
End If
This does change the date, but always sets the time to 1am
Should increment the date if the time is after midday and set the time to 00:00:00
Otherwise just set the time to 00:00:00
It also affects another important program, by causeing it to stop collecting data serially, OK this may not be anything to do with changing the time, but something about that program.
--
So the question is, is there another way to change the Date & Time
In VB6 I could add one to Date, set Time to 00:00:00 and it was done
Can any one suggest a solution
Cheers
Rod