Android Question For-Next-Exit

Giusy

Active Member
Licensed User
Hi,
I have a button called "STOP" when I press it I want to get out of For and Next

B4X:
Fox x = 1 to 100
   .....
   .....
???? <----  the button "Stop" has been pressed and then Exit
   .....
next
It will be very simple for you, but I do not know how to intercept the button :(
Thank you
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Globals
    Dim stop As Boolean
End Sub

For x=1 To 100
        Log(x)
        If stop Then Exit
 Next

Sub Button1_Click
    stop=True
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
also
B4X:
For x = 1 to 100
   .....
   .....
   Sleep(1)
   If ExitVariabile=true then X=101
   .....
next
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Unless you are calling Sleep or Wait For inside the loop then you cannot stop it with an external event.
That's true. So I think something like this should be added:
B4X:
For x=1 To 100
        Log(x)
        Sleep(100)
        If stop Then Exit
Next
 
Upvote 0

Giusy

Active Member
Licensed User
This code will complete in about 1ms. TTS.Speak is not a blocking call (with the exception of the deprecated modal dialogs, there are no blocking methods).

The correct answer is:
B4X:
Sub Button1_Click
 tts.Stop
End Sub
Thank you :D
 
Upvote 0
Top