Hi to all
since the introduction of asyncronous msgboxes, i lost a good part of love for B4A. As a matter of fact, a trivial action like to wait for user interaction, normally managed in "Modal" style (Windows Modal, I mean) became a nightmare, expecially in previous code written with "obsolete" MsgBoxes. My understanding is that, in practice, I must make Apps more or less without relying on the fact that the App waits for user answers. This adds real difficulties to my common Apps. Therefore I decided to try to understand better my faults on this subject, submitting to this community my problem. In the attached code, I have a List, that needs to be changed on User's choice. This code doesn't work, because the ModifyList returns immediately. Maybe the solution is to let the ModifyList sub to wait too.. but it is not so clear to me what to do.
Thanks in advance
since the introduction of asyncronous msgboxes, i lost a good part of love for B4A. As a matter of fact, a trivial action like to wait for user interaction, normally managed in "Modal" style (Windows Modal, I mean) became a nightmare, expecially in previous code written with "obsolete" MsgBoxes. My understanding is that, in practice, I must make Apps more or less without relying on the fact that the App waits for user answers. This adds real difficulties to my common Apps. Therefore I decided to try to understand better my faults on this subject, submitting to this community my problem. In the attached code, I have a List, that needs to be changed on User's choice. This code doesn't work, because the ModifyList returns immediately. Maybe the solution is to let the ModifyList sub to wait too.. but it is not so clear to me what to do.
Thanks in advance
B4X:
Private Sub Button1_Click
Dim i As Int
List1.Initialize
For i=0 To 10
List1.Add(i+1)
Next
Log("Before")
For i=0 To 10
Log(List1.Get(i))
Next
ModifyList(List1)
Log("After")
For i=0 To 10
Log(List1.Get(i))
Next
End Sub
private Sub ModifyList(L As List)
Wait for (Confirm("Modify List?")) Complete (Res As Int)
If Res=DialogResponse.POSITIVE Then
Dim i As Int
For i=0 To 10
L.Set(i,10-i)
Next
End If
End Sub
private Sub Confirm(Msg As String) As ResumableSub
Dim Res As Int
Msgbox2Async(Msg, "Attention", "Yes", "", "No",Null, False)
Wait For Msgbox_Result (Res As Int)
Return Res
End Sub