请问大虾们 这段VB定时关机代码哪里出错

来源:百度知道 编辑:UC知道 时间:2024/06/23 04:23:36
Public a
Public b

Private Sub Form_Click()
a = InputBox("输入你想关机的时间--时(0-23)")
b = InputBox("输入你想关机的时间--分(0-59)")
Me.Caption = "你要关机的时间是" & a & "时" & b & "分"
End Sub

Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()

If Hour(Time) = a And Minute(Time) = b Then
Timer1.Enabled = False
Shell ("shutdown /s /t 60")
End If
End Sub

If Hour(Time) = a And Minute(Time) = b Then改为
If Hour(Time) = val(a) And Minute(Time) = val(b) Then

虽然不懂VB,但是凭感觉应该是If Hour(Time)这里的问题。
Time是什么?是变量没见申明啊?那么只能是库函数了 。那么函数得加括弧吧?应该这样:If Hour(Time())

Public a As Integer, b As Integer

Shell ("shutdown /s /t 60") 改为
Shell "shutdown -s -t 60" '括号可以省略
"shutdown /s /t 60"是 Windows Vista 的关机命令,"shutdown -s -t 60"是 Windows XP 的关机命令
还要把 Public a
Public b
改为 Public a As Integer, b As Integer 或 Dim a As Integer, b As Integer
或者把 If Hour(Time) = a And Minute(Time) = b Then 改为
If Hour(Time) = val(a) And Minute(Time) = val(b) Then

关机代码错误,应该是shell"shutdown-s-t 60",60是秒,可以随便换