Alternative to Wait For (more or less valid)

Star-Dust

Expert
Licensed User
Longtime User
I thought of an alternative to WaitFor.
From the information @Erel has given us, the command is a return, so the code flow continues back to the caller. When the event occurs, it returns to the puntu where it was suspended.

To get a similar thing, I thought that when I raised the event I would have to call the same Sub that was suspended and let it start from the interrupted point. It's not easy but I found a solution that works.

B4X:
Sub ButtonMsgBox_Click
    Dim MsgB As MessageBox
    
    If Not(Sender Is MessageBox) Then
        ' Before
        MsgB.Initialize(Activity,Me,"ButtonMsgBox_Click")
        MsgB.NewMsgBox("What do you want?","Ask","Si","cancel","No")
    Else
        ' After Click
        MsgB = Sender
        ToastResponse(MsgB.Response,"No Wait For")
    End If
End Sub

I used my library to raise as the event the same sub that it generates the class. It works fine without DoEvents at WaitFor.
And you do not have to enter the code into another sub raised by the event
 

Star-Dust

Expert
Licensed User
Longtime User
So this?

B4X:
Sub ButtonMsgBox_Click
    Dim MsgB As MessageBox

    If Not(Sender Is MessageBox) Then
        ' Before
        MsgB.Initialize(Activity,Me,"ButtonMsgBox_Click")
        MsgB.NewMsgBox("What do you want?","Ask","Yes","cancel","No")
    Return
    Else
        ' After Click
        MsgB = Sender
        ToastResponse(MsgB.Response,"No Wait For")
    Return
    End If
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
Sorry, my fault I did not say well.

Those who want to abandon DoEvents may use WaitFor in some cases (such as waiting for dialog boxes) or sleep in other cases.

A second solution is to handle dialogs with events, when an event is raised from the class with CallSub. This solution is used by all alternate dialogue alternatives to native ones.

I was thinking of a third solution, that you do not use the doevent to wait for the click, and not even WaitFor, and I would avoid using the raised event. The solution I have written allows you to manage in a dialog box the moment the call is made (Button_Click) calls the sub caller and continues from the point where it was interrupted.
 

Star-Dust

Expert
Licensed User
Longtime User
I'm taking a dialog box as an example. When the user clicks his choice, the event is raised. This event calls again the Sub calling the dialog class. Within the sub call I verify if it was invoked by the same class, in the positive case it is expressed the choice is the flow proceeds with the code to handle the response of the dialog. I tried it and it works.
 
Top