I have four COMMAND button, each COMMAND has its own code, and now I demand from COMMAND1 run after 5 seconds, COMMAND1 to stop, and then run COMMAND2, automatically stop COMMAND2 again after 5 seconds, and start running COMMAND3, 5 seconds and then stop COMMAND3 and finally running COMMAND4, after 5 seconds, also stop COMMAND4, the future a MSGBOX went, how to write the code?
CodePudding user response:
PRIVATE SUB FORM_LOAD ()
LABEL1. The CAPTION=0 'add a count with
LABEL1. VISABLE=FALSE 'hidden LABEL1
TIMER1. INTERVAL and time control
=1000 'END SUB
Private Sub Timer1_Timer ()
LABEL1. CAPTION=LABEL1. CAPTION + 1
IF LABEL1. CAPTION=5 THEN
COMMAND1_CLICK
IF LABEL1. CAPTION=10 THEN
'stop COMMAND1
'start COMMAND2
IF LABEL1. CAPTION=15
'stop COMMAND2
'start COMMAND3
END the IF
END the IF
END the IF
End Sub
CodePudding user response:
Don't understand ah, I've been will only run Command1 code, will not stop a running Command1, study, etc
CodePudding user response:
refer to the second floor zhufobbs response: don't understand ah, I've been will only run Command1 code, will not stop a running Command1, master of study, such as Command1-4 running time must be less than 5 seconds CodePudding user response:
What did you write in the command code? CodePudding user response:
Timer code is not enough, Dim Running_Index As Integer Private Sub Timer1_Timer () Running_Index=(Running_Index + 1) The Select Case Running_Index Case 2 Command2_Click Case 3 Command3_Click Case 4 Command4_Click In Case the Else Timer1. Enabled=False MsgBox "Stop" End the Select End Sub Private Sub Form_Load () Running_Index=1 Command1_Click Timer1. Inteval=5000 Timer1. Enabled=True End Sub Private Sub Command1_Click . 'in a loop If Running_Index & gt; 1 Then the Exit Sub . End Sub Private Sub Command2_Click . 'in a loop If Running_Index & lt;> 2 Then Exit Sub . End Sub Private Sub Command3_Click . 'in a loop If Running_Index & lt;> 3 Then Exit Sub . End Sub Private Sub Command4_Click . 'in a loop If Running_Index & lt;> 4 Then Exit Sub . End Sub CodePudding user response:
refer to the original poster yfxpw response: I have four COMMAND button, each COMMAND has its own code, and now I demand from COMMAND1 run after 5 seconds, COMMAND1 to stop, and then run COMMAND2, automatically stop COMMAND2 again after 5 seconds, and start running COMMAND3, 5 seconds and then stop COMMAND3 and finally running COMMAND4, after 5 seconds, also stop COMMAND4, the future a MSGBOX went, how to write the code? Shivering with four command button to perform, too! Can make into automatic, CodePudding user response:
The problem seems to be no time more convenient? Call command1_click Start Timer= The Do While the Timer & lt; No start + 5 '5 seconds memory die cycle DoEvents Loop Call command2_click Start Timer= The Do While the Timer & lt; Start + 5 DoEvents Loop Call command3_click Start Timer= The Do While the Timer & lt; Start + 5 DoEvents Loop Call command4_click CodePudding user response:
To what do you mean by numerous check? If your command1 run the program in 5 seconds will not end? CodePudding user response:
If you have the means to stop, then put the code before the call CodePudding user response:
Said, in a TEXTBOX show "AAAAA" after 5 seconds, according to "BBBBB", plus 5 seconds after the show if you write "END"? CodePudding user response:
Private intCount As Integer Private Sub Form_Load () Timer1. Interval=5000 Timer1. Enabled=False End Sub Private Sub Command1_Click () Text1. Text="AAAAA" IntCount=0 Timer1. Enabled=True End Sub Private Sub Timer1_Timer () The Select Case intCount Case 0 Text1. Text="BBBBB" Case 1 Text1. Text="END" Timer1. Enabled=False End the Select IntCount=intCount + 1 End Sub CodePudding user response:
Agree with ah, add a counter IntCount=0 CodePudding user response:
I hope you can understand Option Explicit Dim intCount As Integer Private Sub Command1_Click () Text1. Text="AAAA" End Sub Private Sub Command2_Click () Text1. Text="BBBB" End Sub Private Sub Command3_Click () Text1. Text="CCCC "End Sub Private Sub Command4_Click () Text1. Text="DDDD "End Sub Private Sub Form_Load () IntCount=0 End Sub Private Sub Timer1_Timer () IntCount=intCount + 1 The 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 the Select End Sub CodePudding user response:
Look at your problem description, simply use the Timer is not enough, because VB6 is single thread running, You can try the API to wait for system start time value (ms) continuously do subtraction to get time interval, CodePudding user response:
That,,,, nullnullnullnullnullnullnullnullnull