Android Question MsgBox2 problem

johnerikson

Active Member
Licensed User
Longtime User
Using msgbox2 for Yes/no ouestions result in a uncontrolled jump out- or to the beginning of the Sub!
I Upload a subset of the code in a file to explore the problem!
I use B4A 3.20 on a Dell Workstation with Windows 7 Ultimate and Sumsung S3 Android version 4.3!
I wonder if it is a bug or syntax problem or anything else ....
 

Attachments

  • msgbox2Err.zip
    1.6 KB · Views: 146

johnerikson

Active Member
Licensed User
Longtime User
I've commented the File.Exist check and the log message does appear.

I tested it in Debug (rapid).

If you rotate the screen when the msgbox appears then it will jump back to Activity_Create.

Test it in Release mode and see whether you see this jump.

Thank you Erel!
Something still going wrong with MsgBox2. Even if I reduced the code as below is not running properly. Most of case, not always, I got a jump out of the sub directly after call to MsgBox2. I don't trust it as a solution for a customer. But.......
I have test many alternative, I got best result moving the MsgBox2 into a new code module as function, returning the DialogResponse. After that, in most case the sub behavior as it should, not always.
I hope to find a way to use this extremely necessary function because it seams impossible to create a similarly routine from the basic level!

B4X:
Sub Activity_Create(FirstTime As Boolean)
  
    If FirstTime  Then
        Dim iok As Int
        Dim bRun As Boolean      
        Msgbox("START","") ' Even MsgBox sometime didn't wait for OK Click!
        iok = Msgbox2( "Vill du uppdatera databasen?","Uppdatera", "Ja", "", "Nej",  Null)' It allmost not stay and waiting for a answear!
        'The program jump directly to Activity_Create(FirstTime As Boolean). Sometime you can see the question flash a second!
        Log ("You never reach this point!")
        If iok = DialogResponse.POSITIVE Then
            bRun = True
        Else
            bRun = False
        End If
    End If  
    If bRun = True Then Msgbox("True","") Else Msgbox("False","")
End Sub


I hope that somebody found a way out of this problem"
Johneriksson
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Maybe something like this? (NOT TESTED!)

B4X:
Sub Activity_Create(FirstTime As Boolean)

    ' Or maybe it would work better in Activity_Resume, in which case create a Global Boolean and set it to value of FirstTime and check that in Activity_Resume

    If FirstTime Then
          CallSubDelayed (Me, "PromptForUpdate")
    End If

End Sub

Sub PromptForUpdate
    Dim iok As Int
    Dim bRun As Boolean
    iok = Msgbox2( "Vill du uppdatera databasen?","Uppdatera", "Ja", "", "Nej", Null)

    If iok = DialogResponse.POSITIVE Then
          bRun = True
              Else
              bRun = False
    End If

    If bRun = True Then
          Msgbox("True","")
                Else
                Msgbox("False","")
    End If

End Sub
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
Maybe something like this? (NOT TESTED!)

B4X:
Sub Activity_Create(FirstTime As Boolean)

    ' Or maybe it would work better in Activity_Resume, in which case create a Global Boolean and set it to value of FirstTime and check that in Activity_Resume

    If FirstTime Then
          CallSubDelayed (Me, "PromptForUpdate")
    End If

End Sub

Sub PromptForUpdate
    Dim iok As Int
    Dim bRun As Boolean
    iok = Msgbox2( "Vill du uppdatera databasen?","Uppdatera", "Ja", "", "Nej", Null)

    If iok = DialogResponse.POSITIVE Then
          bRun = True
              Else
              bRun = False
    End If

    If bRun = True Then
          Msgbox("True","")
                Else
                Msgbox("False","")
    End If

End Sub

Thank you for the suggestions!

It doesn't matter what alternative I choose, it results in the same insecurity.
Maybe something like this? (NOT TESTED!)

B4X:
Sub Activity_Create(FirstTime As Boolean)

    ' Or maybe it would work better in Activity_Resume, in which case create a Global Boolean and set it to value of FirstTime and check that in Activity_Resume

    If FirstTime Then
          CallSubDelayed (Me, "PromptForUpdate")
    End If

End Sub

Sub PromptForUpdate
    Dim iok As Int
    Dim bRun As Boolean
    iok = Msgbox2( "Vill du uppdatera databasen?","Uppdatera", "Ja", "", "Nej", Null)

    If iok = DialogResponse.POSITIVE Then
          bRun = True
              Else
              bRun = False
    End If

    If bRun = True Then
          Msgbox("True","")
                Else
                Msgbox("False","")
    End If

End Sub

Thank you very much for all suggestions!

It seams that I have to found a another solution. It doesn't matter what alternative I choose, it result in same insecurity. All other parts I use of B4a environment is running well so on one way or another I solve this problem!
CallSubDelayed is special since it don't return to the caller, but it should not help in this case! Maybe it depends on my environment and equipment!

I guess I pop up in another thread!
Johneriksson
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
Thanks for interest and involvement!

All modes! However, I have not tested it on another computer yet, later on.

It's very interesting to go on researching what it is witch cause that difficulties!
At the same time, it is imperative to push ahead with the project and not only focus
on MsgBox2. perhaps in a new release of B4A or other environments it disappear.
At present I solved it with menu alternative if MsgBox2 not succeed.
I have discovered many difference between developing Apps on Mobiles and Desktop Application on PC!
So I have much to educate!, but much have been done on short time!

Johneriksson
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Hmm...I know this thread is rather old however,

I have also this problem but for me it only happens with 4.0.3 (in my case with my Acer A500).

I managed to resolve the problem using SELECT CASE instead of an IF-statement

B4X:
Select Msgbox2("Is this a test?","Testing Msgbox2 problem", "Yes", "", "No", Null)
   Case DialogResponse.POSITIVE
      myvariable = True
   Case DialogResponse.NEGATIVE
      myvariable = False
End Select

Maybe it is related to the IF-statement?

Hope this may help anyone else who may get this error.
 
Upvote 0

charmander

New Member
Licensed User
Longtime User
the problem is: Msgbox, msgobx2 and DoEvents crashing each other. if you use DoEvents function in a loop (esipecially in forever loops or forever threads) it is crashing with msgboxes and dialog boxes don't wait your response. But sometimes you have to use this functions. So you can use a global variable (boolean). before showing the msgbox set its value to true and after close (any button clicked) set again to false. And change all of the lines where you use DoEvents functions as "if <your variable> = false then DoEvents". This will fix your issue.
 
Last edited:
Upvote 0
Top