PRIVATE SUB FORM_LOAD() LABEL1.CAPTION=0 '加个计数用的 LABEL1.VISABLE=FALSE '隐藏LABEL1 TIMER1.INTERVAL=1000 '加时间控件 END SUBPrivate Sub Timer1_Timer() LABEL1.CAPTION=LABEL1.CAPTION+1 IF LABEL1.CAPTION=5 THEN COMMAND1_CLICK IF LABEL1.CAPTION=10 THEN '停止COMMAND1 '开始COMMAND2 IF LABEL1.CAPTION=15 '停止COMMAND2 '开始COMMAND3 END IF END IF END IF End Sub
仅有定时器代码是不够的。Dim Running_Index As IntegerPrivate Sub Timer1_Timer() Running_Index = (Running_Index + 1) Select Case Running_Index Case 2 Command2_Click Case 3 Command3_Click Case 4 Command4_Click Case Else Timer1.Enabled = False MsgBox "Stop" End Select End SubPrivate Sub Form_Load() Running_Index = 1 Command1_Click Timer1.Inteval = 5000 Timer1.Enabled = True End SubPrivate Sub Command1_Click ...... '在循环中 If Running_Index > 1 Then Exit Sub ...... End SubPrivate Sub Command2_Click ...... '在循环中 If Running_Index <> 2 Then Exit Sub ...... End SubPrivate Sub Command3_Click ...... '在循环中 If Running_Index <> 3 Then Exit Sub ...... End SubPrivate Sub Command4_Click ...... '在循环中 If Running_Index <> 4 Then Exit Sub ...... End Sub
这个问题好象不用定时更方便吧? call command1_click start = Timer Do While Timer < start + 5'不占用内存5秒死循环 DoEvents Loop call command2_click start = Timer Do While Timer < start + 5 DoEvents Loop call command3_click start = Timer Do While Timer < start + 5 DoEvents Loop call command4_click
Private intCount As IntegerPrivate Sub Form_Load() Timer1.Interval = 5000 Timer1.Enabled = False End SubPrivate Sub Command1_Click() Text1.Text = "AAAAA" intCount = 0 Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() Select Case intCount Case 0 Text1.Text = "BBBBB" Case 1 Text1.Text = "END" Timer1.Enabled = False End Select
intCount = intCount + 1 End Sub
同意啊,再加一个计数器 intCount = 0
希望你能明白 Option Explicit Dim intCount As IntegerPrivate Sub Command1_Click() Text1.Text = "AAAA" End SubPrivate Sub Command2_Click() Text1.Text = "BBBB" End SubPrivate Sub Command3_Click() Text1.Text = "CCCC" End SubPrivate Sub Command4_Click() Text1.Text = "DDDD" End SubPrivate Sub Form_Load() intCount = 0 End SubPrivate Sub Timer1_Timer() intCount = intCount + 1 Select Case intCount Case 1 Call command1_click Case 2 Call command2_click Case 3 Call command3_click Case 4 Call command4_click Case 5 MsgBox "EEEE" End Select End Sub
LABEL1.CAPTION=0 '加个计数用的
LABEL1.VISABLE=FALSE '隐藏LABEL1
TIMER1.INTERVAL=1000 '加时间控件
END SUBPrivate Sub Timer1_Timer()
LABEL1.CAPTION=LABEL1.CAPTION+1
IF LABEL1.CAPTION=5 THEN
COMMAND1_CLICK
IF LABEL1.CAPTION=10 THEN
'停止COMMAND1
'开始COMMAND2
IF LABEL1.CAPTION=15
'停止COMMAND2
'开始COMMAND3
END IF
END IF
END IF
End Sub
Running_Index = (Running_Index + 1)
Select Case Running_Index
Case 2
Command2_Click
Case 3
Command3_Click
Case 4
Command4_Click
Case Else
Timer1.Enabled = False
MsgBox "Stop"
End Select
End SubPrivate Sub Form_Load()
Running_Index = 1
Command1_Click
Timer1.Inteval = 5000
Timer1.Enabled = True
End SubPrivate Sub Command1_Click
...... '在循环中
If Running_Index > 1 Then Exit Sub
......
End SubPrivate Sub Command2_Click
...... '在循环中
If Running_Index <> 2 Then Exit Sub
......
End SubPrivate Sub Command3_Click
...... '在循环中
If Running_Index <> 3 Then Exit Sub
......
End SubPrivate Sub Command4_Click
...... '在循环中
If Running_Index <> 4 Then Exit Sub
......
End Sub
call command1_click
start = Timer
Do While Timer < start + 5'不占用内存5秒死循环
DoEvents
Loop
call command2_click
start = Timer
Do While Timer < start + 5
DoEvents
Loop
call command3_click
start = Timer
Do While Timer < start + 5
DoEvents
Loop
call command4_click
是不是你的command1中的程序5秒运行不会结束的?
Private intCount As IntegerPrivate Sub Form_Load()
Timer1.Interval = 5000
Timer1.Enabled = False
End SubPrivate Sub Command1_Click()
Text1.Text = "AAAAA"
intCount = 0
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
Select Case intCount
Case 0
Text1.Text = "BBBBB"
Case 1
Text1.Text = "END"
Timer1.Enabled = False
End Select
intCount = intCount + 1
End Sub
intCount = 0
Option Explicit
Dim intCount As IntegerPrivate Sub Command1_Click()
Text1.Text = "AAAA"
End SubPrivate Sub Command2_Click()
Text1.Text = "BBBB"
End SubPrivate Sub Command3_Click()
Text1.Text = "CCCC"
End SubPrivate Sub Command4_Click()
Text1.Text = "DDDD"
End SubPrivate Sub Form_Load()
intCount = 0
End SubPrivate Sub Timer1_Timer()
intCount = intCount + 1
Select Case intCount
Case 1
Call command1_click
Case 2
Call command2_click
Case 3
Call command3_click
Case 4
Call command4_click
Case 5
MsgBox "EEEE"
End Select
End Sub
你可以试试API来等到系统启动的时间值(毫秒)不断做减法来得到时间间隔。
Timer 必须在代码编译成 .exe 之后,才能执行类似“中断”的功能。不要在调试状态下测试。