VB计时器问题。。

来源:百度知道 编辑:UC知道 时间:2024/05/18 16:12:00
我想做个计时器,时间一到就打开程序。可是程序却一直打开。。停止不了
高手指点下啊... 顺便再问下。怎么能做到 时间一到,程序一打开就结束计时器程序?

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

Private Sub Timer1_Timer()
Static Count As Integer
Count = IIf(Count < 120, Count + 1, 120)
If Count = 120 Then MsgBox "时间到": Timer1.Enabled = False
Shell "X:\XX.exe"
End Sub
一楼的---提示语句错误
二楼的---程序无反应,没自动打开程序
三楼的---就是X:\XX.exe一打开,计时器(生成EXE后的)自动关闭

哈!
问题就在Shell "X:\XX.exe" 上,
你这样的话程序每1000毫秒会打开
"X:\XX.exe" 一次。

把代码修改一下:
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Static Count As Integer
Count = IIf(Count < 120, Count + 1, 120)
If Count = 120 Then MsgBox "时间到"
If Count = 120 Then Shell "X:\XX.exe"
If Count = 120 Then Timer1.Enabled =False
End Sub

这样时间一到,程序一打开就结束计时器程序
你试一试吧!

tongyi

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

Private Sub Timer1_Timer()
Static Count As Integer
Count = IIf(Count < 120, Count + 1, 120)
If Count = 120 Then MsgBox "时间到": Timer1.Enabled = False
Shell "X:\XX.exe"
End '或者加unload me
End Sub

'这里end表示强制的结束进程,unload(From.hWnd )这里表示卸载指定窗体,(From.hWnd ).Hide 这里表示隐