Hi,
I am trying to write an application which corrects the system time. According to the Microsoft web site (MSDN), the way to do this from Visual Basic 6.0 is to include the following API-calling code:
Option Explicit
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime _
As SYSTEMTIME) As Long
Private Sub Form_Load()
Dim lReturn As Long
Dim lpSystemTime As SYSTEMTIME
lpSystemTime.wYear = 1996
lpSystemTime.wMonth = 6
lpSystemTime.wDayOfWeek = 5
lpSystemTime.wDay = 28
lpSystemTime.wHour = 9
lpSystemTime.wMinute = 42
lpSystemTime.wSecond = 0
lpSystemTime.wMilliseconds = 0
lReturn = SetSystemTime(lpSystemTime)
End Sub
This however, only works under VB 6.0. Whatever I do, I cannot get this code to work under Visual Basic .NET. I realise that there need to be some changes to the code to get i to compile. That is, you can't use Option Explicit under VB .NET, the word Structure has to be used instead of Type and the function declaration requires ByRef before the argument. So my code looks like this:
Private Structure SYSTEMTIME
Public wYear As Integer
Public wMonth As Integer
Public wDayOfWeek As Integer
Public wDay As Integer
Public wHour As Integer
Public wMinute As Integer
Public wSecond As Integer
Public wMilliseconds As Integer
End Structure
Private Declare Function SetSystemTime Lib "kernel32" (ByRef lpSystemTime _
As SYSTEMTIME) As Long
Private Sub Form_Load()
Dim lReturn As Long
Dim lpSystemTime As SYSTEMTIME
lpSystemTime.wYear = 1996
lpSystemTime.wMonth = 6
lpSystemTime.wDayOfWeek = 5
lpSystemTime.wDay = 28
lpSystemTime.wHour = 9
lpSystemTime.wMinute = 42
lpSystemTime.wSecond = 0
lpSystemTime.wMilliseconds = 0
lReturn = SetSystemTime(lpSystemTime)
End Sub
But it still doesn't work; producing a DLL error 87 (The parameter is invalid) when executing the last line.
Any ideas?
Dan Griffiths
Software Analyst
National Grid Transco (NGT)
I am trying to write an application which corrects the system time. According to the Microsoft web site (MSDN), the way to do this from Visual Basic 6.0 is to include the following API-calling code:
Option Explicit
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime _
As SYSTEMTIME) As Long
Private Sub Form_Load()
Dim lReturn As Long
Dim lpSystemTime As SYSTEMTIME
lpSystemTime.wYear = 1996
lpSystemTime.wMonth = 6
lpSystemTime.wDayOfWeek = 5
lpSystemTime.wDay = 28
lpSystemTime.wHour = 9
lpSystemTime.wMinute = 42
lpSystemTime.wSecond = 0
lpSystemTime.wMilliseconds = 0
lReturn = SetSystemTime(lpSystemTime)
End Sub
This however, only works under VB 6.0. Whatever I do, I cannot get this code to work under Visual Basic .NET. I realise that there need to be some changes to the code to get i to compile. That is, you can't use Option Explicit under VB .NET, the word Structure has to be used instead of Type and the function declaration requires ByRef before the argument. So my code looks like this:
Private Structure SYSTEMTIME
Public wYear As Integer
Public wMonth As Integer
Public wDayOfWeek As Integer
Public wDay As Integer
Public wHour As Integer
Public wMinute As Integer
Public wSecond As Integer
Public wMilliseconds As Integer
End Structure
Private Declare Function SetSystemTime Lib "kernel32" (ByRef lpSystemTime _
As SYSTEMTIME) As Long
Private Sub Form_Load()
Dim lReturn As Long
Dim lpSystemTime As SYSTEMTIME
lpSystemTime.wYear = 1996
lpSystemTime.wMonth = 6
lpSystemTime.wDayOfWeek = 5
lpSystemTime.wDay = 28
lpSystemTime.wHour = 9
lpSystemTime.wMinute = 42
lpSystemTime.wSecond = 0
lpSystemTime.wMilliseconds = 0
lReturn = SetSystemTime(lpSystemTime)
End Sub
But it still doesn't work; producing a DLL error 87 (The parameter is invalid) when executing the last line.
Any ideas?
Dan Griffiths
Software Analyst
National Grid Transco (NGT)