主题:求助,VB.Net设置系统时间问题
我调用API函数“SetSystemTime”设置时间的时候老是出现“未将对象引用设置到对象的实例”的错误。
具体代码如下(我忽略了部分自动生成的代码):
'类型的定义
Public 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 Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'定义变量
Dim T1 As New SYSTEMTIME
'设置变量
T1.wYear = 2005
T1.wMonth = 1
T1.wDay = 1
T1.wHour = 12
T1.wMinute = 1
T1.wSecond = 2
'调用API设置时间。(下面这句出错!!!)
SetSystemTime(T1)
End Sub
详细错误信息如下:
未处理的“System.NullReferenceException”类型的异常出现在 Test1.exe 中。
其他信息: 未将对象引用设置到对象的实例。
具体代码如下(我忽略了部分自动生成的代码):
'类型的定义
Public 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 Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'定义变量
Dim T1 As New SYSTEMTIME
'设置变量
T1.wYear = 2005
T1.wMonth = 1
T1.wDay = 1
T1.wHour = 12
T1.wMinute = 1
T1.wSecond = 2
'调用API设置时间。(下面这句出错!!!)
SetSystemTime(T1)
End Sub
详细错误信息如下:
未处理的“System.NullReferenceException”类型的异常出现在 Test1.exe 中。
其他信息: 未将对象引用设置到对象的实例。