Bug? Data is display is incorrect order?

Theera

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub Button1_Click
    xui.MsgboxAsync(name, "B4X")
    xui.MsgboxAsync(age, "B4X")
End Sub

I think that the name must be shown the first,but why is the age shown the first.
 

emexes

Expert
Licensed User
Probably because they both displayed quickly one after the other in sequence, without waiting for user input in-between (ie Async) and so what you see is two dialog boxes, with the "age" dialog box top, because it was the most-recently displayed.

Ok, ok, you don't actually see the "name" dialog box (unless you have x-ray vision) because it's hidden behind the "age" dialog box that is on top of it.

But when you close that top one, the underneath dialog box - which has been hiding there the entire time - is revealed.
 
Last edited:

emexes

Expert
Licensed User
the name must be shown the first

An easy fix here would be to reverse the dialog box display sequence, so that the input you'd like FIRST is the TOP (last-displayed) dialog box.

But a better way might be to bring up the first dialog box FIRST (ie, in the order that you'd expect to be programming it) and THEN in the event that handles valid input from that, bring up the second dialog box (ie after the first dialog box has been successfully answered).

That way, if the user cancels out of the first dialog box, then the input trail stops there, without forcing the user to also have to cancel the second (and third and fourth...) dialog boxes that presumably no longer apply since the user has indicated they want to bail out of the data entry sequence.
 

walt61

Active Member
Licensed User
Longtime User
The easiest would be to outfit users with X-ray vision as @emexes suggested :D Failing that, what he means is this:
B4X:
    Dim name As String = "John Doe"
    Dim age As String = "50"
    Wait For (xui.MsgboxAsync(name, "B4X")) Msgbox_Result(ignoredDialogResponse As Int)
    Wait For (xui.MsgboxAsync(age, "B4X")) Msgbox_Result(ignoredDialogResponse As Int)
 

Theera

Well-Known Member
Licensed User
Longtime User
The easiest would be to outfit users with X-ray vision as @emexes suggested :D Failing that, what he means is this:
B4X:
    Dim name As String = "John Doe"
    Dim age As String = "50"
    Wait For (xui.MsgboxAsync(name, "B4X")) Msgbox_Result(ignoredDialogResponse As Int)
    Wait For (xui.MsgboxAsync(age, "B4X")) Msgbox_Result(ignoredDialogResponse As Int)
Assume I have tried to add more commands ,the results are pop-stack.
B4X:
Private Sub Button1_Click
    xui.MsgboxAsync(name, "B4X")
    xui.MsgboxAsync(age, "B4X")
    xui.MsgboxAsync(sex, "B4X")
End Sub

it shows the sex the first,and then the age and the last is the name.
 

Theera

Well-Known Member
Licensed User
Longtime User
That's because you didn't do what I suggested, but just repeated what you were doing :) Use 'Wait For'!
I think the method you suggest is to solve the problem at the root cause (not the problem at the root).(Google translate)
 

emexes

Expert
Licensed User
THEN in the event that handles valid input from that, bring up the second dialog box (ie after the first dialog box has been successfully answered).

Why is WaitFor, which is effectively reimplementing the old-style modal dialogs, the apparently-preferred method here? What am I not seeing?
 

agraham

Expert
Licensed User
Longtime User
WaitFor, which is effectively reimplementing the old-style modal dialogs
It isn't really. Your suggestion is in fact equivalent to using WaitFor in that in both cases execution returns to the message loop until the user closes the dialog and the event is raised. I would use consecutive WaitFors as it puts the logic for displaying successive dialog boxes 'in-line' where it is more obvious what is happening rather than scattering any decision making code around other event Subs.
 

Sagenut

Expert
Licensed User
Longtime User
If you are going to show more messages you could try this to avoid rewriting the same line multiple times
B4X:
Private Sub Button2_Click
    Show(Array As String("Name", "Age", "Sex"))    'Here you can add all the messages to be shown in sequence
End Sub

Private Sub Show (texts() As String)
    For Each Msg As String In texts
        Wait For (xui.MsgboxAsync(Msg, "B4X")) Msgbox_Result(ignoredDialogResponse As Int)
    Next
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
Maybe in your case a Toast would be better?
B4X:
Dim Toast As BCToast
Toast.Initialize(Root)
Toast.DurationMs = 1000
Toast.Show("Message")

P.S. No, also because you should write as follows:
B4X:
Dim Toast As BCToast
Toast.Initialize(Root)
Toast.DurationMs = 1000
Toast.Show(name)
Sleep(1000)
Toast.Show(age)
 
Top