VB中如何用时钟控件控制一个程序在一段时间后开始和结束
1个回答
2013-06-13
展开全部
假设你现在要在12点启动系统的计算器程序,在12点01分结束,那就新建一个窗体,画一个timer控件,将其interval 设为1000,在代码区复制以下代码Option Explicit
Dim started As BooleanPrivate Sub Timer1_Timer()
If Val(Hour(Now)) = 12 And Val(Minute(Now)) = 0 And started = False Then
started = True
Shell "cmd /c calc", vbHide
End If
If started = True And Val(Minute(Now)) = 1 Then
Shell "cmd /c taskkill /f /im calc.exe", vbHide
Timer1.Enabled = False
End If
End Sub 测试已通过
Dim started As BooleanPrivate Sub Timer1_Timer()
If Val(Hour(Now)) = 12 And Val(Minute(Now)) = 0 And started = False Then
started = True
Shell "cmd /c calc", vbHide
End If
If started = True And Val(Minute(Now)) = 1 Then
Shell "cmd /c taskkill /f /im calc.exe", vbHide
Timer1.Enabled = False
End If
End Sub 测试已通过
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询