Home > Software engineering >  Worry, if I want to use a button to let another button in the loop terminates, be sure to use multit
Worry, if I want to use a button to let another button in the loop terminates, be sure to use multit

Time:10-15

Is not the timer, is for the loop hair serial command, want to use button2 to terminate it!!!!!
Thanks!!!!!!

CodePudding user response:

Nobody????????????

CodePudding user response:

Is loop hair in for the serial command to add a condition judgment, button2 set when the condition is false...

CodePudding user response:

refer to the second floor Topc008 response:
is for loop hair serial command to add a condition judgment, button2 set when the condition is false...

In a loop, there must be at least 1 DoEvents, this is very important...

CodePudding user response:

No, can be done with the help of a public variables:
 Dim blnStop As Boolean 

Private Sub Command1_Click ()
BlnStop=False
Do Until blnStop
'perform the function of your application here

DoEvents' allow other control operation and detection system message
Loop
End Sub

Private Sub Command2_Click ()
BlnStop=True
End Sub

CodePudding user response:

I am using a for loop

B=0
Dim As Integer I

For I=0 To 35

If b=1 Then the Exit For
End the If
Command1 (I)=True
Next I

Private Sub Command2_Click ()

B=1

End Sub


How doevents added here????????????????

CodePudding user response:

You this may be too late point were running up the second button,
 
Dim As Integer b

Private Sub Command1_Click ()
Dim As Integer I
B=0
For I=0 To 35
DoEvents
If b=1 Then the Exit For
Command1 (I)=True
Next I
End Sub

Private Sub Command2_Click ()
B=1
End Sub