我想做个定时自动关机的软件,具体要求是在对话框上输入时间和分钟就能自动在输入时见内自动关机,可是代码没用,是不是在调用时只能调用系统自己东西?
具体代码是这样的,请高手看下。
Private Sub Command1_Click()
Dim a As String
Dim b As String
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > 24 Or b >= 60 Then
MsgBox "小时数必须是0-24,分钟数必须是0-59。"
Else
Shell ("at a:b shutdown -s -t 10 -c 启动自动关机")
MsgBox ("系统将在" & a & ":" & b & "关闭")
End If
End Sub
请问要怎么修改才能达到我想要的目的?
代码如下:
Private Sub Command2_Click()
Timer1.Enabled = False
Text1.Enabled = True
Text2.Enabled = True
MsgBox "取消成功!", 64, "信息"
End Sub
Private Sub Form_Load()
Text1.MaxLength = 2
Text2.MaxLength = 2
Timer1.Enabled = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) 'text1.text只能输入数字
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
Exit Sub
ElseIf KeyAscii = vbKeyReturn Then
Call Command1_Click
Else
KeyAscii = 0
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer) 'text2.text 只能输入数字
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
Exit Sub
ElseIf KeyAscii = vbKeyReturn Then
Call Command1_Click
Else
KeyAscii = 0
End If
End Sub
Private Sub Command1_Click()
On Error Resume Next
If Text1.Text > 23 Then
MsgBox "小时数必须是0-24,分钟数必须是0-59。", 16, "提示"
ElseIf Text2.Text > 59 Then
MsgBox "小时数必须是0-24,分钟数必须是0-59。", 16, "提示"
Else
MsgBox " 程序将在: " & Text1.Text & ":" & Text2.Text & "关闭, 64, """
Timer1.Enabled = True
Text1.Enabled = False
Text2.Enabled = False
End If
End Sub
Private Sub Timer1_Timer()
If Text1.Text & ":" & Text2.Text & ":00" = Time Then
Shell "cmd.exe /c shutdown.exe -s -t 10", vbHide
End If
End Sub
加我QQ,交流VB 我也是爱学VB 的,,,, 嘿嘿,这个代码是我刚才写的,给分吧~~~ o(∩_∩)o
Private Sub Command1_Click()
Dim a, b As Integer
If Len(Text1.Text) > 0 And Len(Text2.Text) > 0 Then
a = CInt(Text1.Text)
b = CInt(Text2.Text)
If a > 24 Or b >= 60 Then
MsgBox "小时数必须是0-24,分钟数必须是0-59。"
Else
Shell ("at " & a & ":" & b & "shutdown -s -t 10 -c")
MsgBox ("系统将在" & a & ":" & b & "关闭")
End If
Else
MsgBox "请输入小时和分钟数。", vbExclamation, "提示"
End If
End Sub