Android Question Is there any way to stop the previous event when I start the new event?

gilsonmv

Member
Hey, guys
Is there any way to stop the previous event when I start the new event?
example:
When I press the button the routine will show me 1, 2, 3, 4.
If I press the button again, I want the previous event to be stopped before the new event starts.
ex. 1,2 (I pressed the button) 1,2,3,4.
thanks


B4X:
Sub PanelEdBtPlay_Click

    edEfeito.Text = "1 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
    
    edEfeito.Text = "2 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
    
    edEfeito.Text = "3 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
    
    edEfeito.Text = "4 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
        
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes. You need the "index pattern" here: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-and-the-index-pattern.111487/#content

B4X:
Sub PanelEdBtPlay_Click
    PanelEdByPlayIndex = PanelEdByPlayIndex + 1 'global variable
    Dim MyIndex = PanelEdByPlayIndex
    edEfeito.Text = "1 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
    If MyIndex <> PanelEdByPlayIndex Then Return

    edEfeito.Text = "2 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
        If MyIndex <> PanelEdByPlayIndex Then Return

    edEfeito.Text = "3 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
        If MyIndex <> PanelEdByPlayIndex Then Return

    edEfeito.Text = "4 "
    EditText1.Text = edEfeito.Text
    SendMessage(Array As Byte(EditText1.Text))
    edLogTemp.Text = edLogTemp.Text & EditText1.Text
    Sleep(1000)
            If MyIndex <> PanelEdByPlayIndex Then Return
End Sub
 
Upvote 0

gilsonmv

Member
Great!!
I declared "PanelEdByPlayIndex" as a global variable and your routine worked perfectly!
Thank you very much.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim PanelEdByPlayIndex As Int
End Sub
 
Upvote 0
Top