With
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
to pass all necessary arguments via Params. see Code Msgbox3
Code Msgbox2
Code Msgbox3
B4X:
Msgbox2 (EventName As String, Message As String, Title As String, Buttons As List)
and we have to use code like see Code Msgbox2:It is not possible to halt the code execution when showing a msgbox.
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)
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: