Wish Msgbox3

b4auser1

Well-Known Member
Licensed User
Longtime User
With
B4X:
  Msgbox2 (EventName As String, Message As String, Title As String, Buttons As List)
It is not possible to halt the code execution when showing a msgbox.
and we have to use code like see Code Msgbox2:
If we need to pass argumement to Msg_Click, then we have to use variables in Process_Globals. It's not convinient and make code less readable and supportive. I propose to add
B4X:
  Msgbox3 (EventName As String, Message As String, Title As String, Buttons As List, Params() As Object)
to pass all necessary arguments via Params. see Code Msgbox3

Code Msgbox2
B4X:
Sub Process_Globals
   dim dothis as int
End Sub

'......

Sub Button1_Click
    cmsg2("Button1 Title","Button1 performed a Msgbox",1)
End Sub

Sub Button2_Click
    cmsg2("Button2 Title","Button2 performed a Msgbox",2)
End Sub

Sub Button3_Click
    cmsg2("Button3 Title","Button3 performed a Msgbox",3)
End Sub

Sub Button4_Click
    cmsg2("Button4 Title","Button4 performed a Msgbox",4)
End Sub


Sub cmsg2(title as string, msgstr as string, action as int)
   dothis = action
   Msgbox2("Msg", title, msgstr, Array("yes","no"))
end sub

Sub Msg_Click(ButtonText As String)

If ButtonText = "yes" Then
    if dothis = 1 Then log("action1 - Button1_clicked")
    if dothis = 2 Then log("action2 - Button2_clicked")
    if dothis = 3 Then log("action3 - Button3_clicked")
    if dothis = 4 Then log("action4 - Button4_clicked")
Else If ButtonText = "no" Then
    Log("no pressed")
End If

End Sub

Code Msgbox3
B4X:
Sub Process_Globals
End Sub

'......

Sub Button1_Click
    cmsg2("Button1 Title","Button1 performed a Msgbox",1)
End Sub

Sub Button2_Click
    cmsg2("Button2 Title","Button2 performed a Msgbox",2)
End Sub

Sub Button3_Click
    cmsg2("Button3 Title","Button3 performed a Msgbox",3)
End Sub

Sub Button4_Click
    cmsg2("Button4 Title","Button4 performed a Msgbox",4)
End Sub


Sub cmsg2(title as string, msgstr as string, action as int)
   dothis = action
   Msgbox3("Msg", title, msgstr, Array("yes","no"), Array(action))
end sub

Sub Msg_Click(ButtonText As String, Params() As Object)

If ButtonText = "yes" Then
dim dothis as int = Params(0)
    if dothis = 1 Then log("action1 - Button1_clicked")
    if dothis = 2 Then log("action2 - Button2_clicked")
    if dothis = 3 Then log("action3 - Button3_clicked")
    if dothis = 4 Then log("action4 - Button4_clicked")
Else If ButtonText = "no" Then
    Log("no pressed")
End If

End Sub
 
Last edited:

b4auser1

Well-Known Member
Licensed User
Longtime User
It is technically not possible to implement modal dialogs in iOS.
I know. I do not propose to implement modal dialogs. I propose to pass args via Params to MsgBox callback to avoid using global variables as store for arguments.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see. It can be useful.

Note that for now you can use different subs. You don't need to use global variables.
B4X:
Sub Button_Click
Dim b As Button = Sender
Dim number As Int = b.Tag '<-- the number is stored in the button's tag property
Msgbox("Msg" & number, $"Button${number} performed a Msgbox")
End Sub

Sub Msg1_Click(ButtonText As String)
Msg(ButtonText, 1)
End Sub
Sub Msg2_Click(ButtonText As String)
Msg(ButtonText, 2)
End Sub
Sub Msg3_Click(ButtonText As String)
Msg(ButtonText, 3)
End Sub
Sub Msg4_Click(ButtonText As String)
Msg(ButtonText, 4)
End Sub

Sub Msg(ButtonText As String, Number As Int)
'...
End Sub
 

b4auser1

Well-Known Member
Licensed User
Longtime User
I created samples of code to clarify my wish

B4A:
B4X:
Sub Process_Globals

    Type Row_Type (value1 As String, value21 As String, value22 As String)
End Sub

Sub SelectValues
    Dim l_row As Row_Type : l_row.Initialize

   l_row.value1 = "1"

    Select Msgbox2("value 21 or value 22 or cancel", "Select", "value 21", "value 22", "Cancel", Null)
    Case DialogResponse.POSITIVE
        l_row.value21 = "21"
        l_row.value22 = "-"
    Case DialogResponse.NEGATIVE
        l_row.value21 = "-"
        l_row.value22 = "22"
    Case DialogResponse.CANCEL
        Return
    End Select
   
    ProcessRow(l_row)   

End Sub

Sub ProcessRow(a_row As Row_Type)
...
End Sub

B4i MsgBox2:
B4X:
Sub Process_Globals

    Type Row_Type (value1 As String, value21 As String, value22 As String)

   Dim g_row As Row_Type : 

End Sub

Sub SelectValues
  g_row.Initialize

    g_row.value1 = "1"

    Msgbox2("Msg", "value 21 or value 22 or cancel", "Select", Array("value 21","value 22", "Cancel"))
   
End Sub

Sub Msg_Click(ButtonText As String)

    Select ButtonText
    Case "value 21"
        g_row.value21 = "21"
        g_row.value22 = "-"
    Case "value 22"
        g_row.value21 = "-"
        g_row.value22 = "22"
    Case "Cancel"
        Return
    End Select

    ProcessRow(g_row)  

End Sub

Sub ProcessRow(a_row As Row_Type)
...
End Sub

B4i MsgBox3:
B4X:
Sub Process_Globals

    Type Row_Type (value1 As String, value21 As String, value22 As String)
End Sub

Sub SelectValues
    Dim l_row As Row_Type : l_row.Initialize

    l_row.value1 = "1"

    Msgbox3("Msg", "value 21 or value 22 or cancel", "Select", Array("value 21","value 22", "Cancel"), Array(l_row))
   
End Sub

Sub Msg_Click(ButtonText As String, Params() As Object)
   Dim l_row As Row_Type = Params(0)

    Select ButtonText
    Case "value 21"
        l_row.value21 = "21"
        l_row.value22 = "-"
    Case "value 22"
        l_row.value21 = "-"
        l_row.value22 = "22"
    Case "Cancel"
        Return
    End Select

    ProcessRow(l_row)  

End Sub

Sub ProcessRow(a_row As Row_Type)
...
End Sub
 
Top