Wish AsyncMessage Selfcontrol...

BlueVision

Well-Known Member
Licensed User
Longtime User
This is just a small, convenient feature, but it may be easy to implement.
I often generate runtime-dependent popups via AsyncMessages in my programs, they are simply best suited for this. A small, nice additional feature would be a ‘RunOnce’ option. In other words: the AsyncMessage only comes up once and does not have to be answered again and again. I currently prevent this with a boolean variable in the program that is set when the message is answered.
I think many other programmers would also appreciate this small enhancement.

Cheers BV
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Here is way - still not ideal - but doable. The msg string is replaced by the result after the first show.
There are two versions, the second, "onceMsgNoWait" is a simple notice version, that is only shown once.

B4X:
Private Sub CallingSub
    Dim msg1() As Object = Array("Do you know what you're doing?","Caution", "Yes", "Cancel", "No", Null)

    Wait For(onceMsg(msg1)) Complete (success As Boolean)
    Log("Done 1: " & msg1(0))

    Wait For(onceMsg(msg1)) Complete (success As Boolean)
    Log("Done 2: " & msg1(0))

    'OR if no answer expected and no need to wait ...
    
    Dim msg2() As Object = Array("Be careful!","Caution")

    onceMsgNoWait(msg2)
    Log("Done 3")

    onceMsgNoWait(msg2)
    Log("Done 4")
End Sub

Public Sub onceMsg(msg() As Object) As ResumableSub
    If Not(msg(0) Is Int) Then
        Dim sf As Object = xui.Msgbox2Async(msg(0), msg(1), msg(2), msg(3), msg(4), msg(5))
        Wait For (sf) Msgbox_Result (result As Int)
        msg(0) = result
        Return True
    Else
        Return False
    End If
End Sub

Public Sub onceMsgNoWait(msg() As Object)
    If Not(msg(0) Is Int) Then
        xui.MsgboxAsync(msg(0), msg(1))
        msg(0) = 0
    End If
End Sub
 

BlueVision

Well-Known Member
Licensed User
Longtime User
William, I admire your enthusiasm, but I don't think the effort you put into it justifies the benefit. It makes the code very confusing overall and difficult to understand. This is one of those things where, after several months, you wonder ‘what the hell I did here’?
It works and is a different approach, but I think my IF-THEN CONSTRUCTION around the AsyncMessage with an additional TRUE-FALSE VARIABLE is a little more transparent.
But thanks for your idea.
Generally speaking, B4X isn't dead just because Erel hasn't implemented it yet. It all depends on the effort it takes him to do so.
I only came across it today. I had generated an AsyncMessage popup when clicking in a B4X table. It's annoying when the popup keeps reappearing with every click.
 

BlueVision

Well-Known Member
Licensed User
Longtime User
Thanks for responding Erel. Well, you are right, it's easy to implement with a flag set while while reacting to the the first occurance of the message. It was just a question of comfort.
 
Top