Android Question Strange If Else... behavior

Computersmith64

Well-Known Member
Licensed User
Longtime User
I have the following piece of code in a sub in one of my apps:

B4X:
'cDlg is a Custom Dialog
cDlg.ShowAsync(mName.Trim, "Close", "", alertText, LoadBitmap(File.DirAssets, "ic_info_outline_black_24dp.png"), True)
cDlg.SetSize(100%x, 405dip)
Wait For Dialog_Ready(pnl As Panel)
pnl.LoadLayout("popup")
Wait For Dialog_Result(res As Int)
If res = DialogResponse.NEGATIVE Then
    If alertText = "Set Alert" Then CallSub3(Starter, "setAlert", mIndex, mTimeLeft * 1000) Else CallSub2(Starter, "cancelAlert", mIndex)
End If

The If part (the call to "setAlert") works fine every time, however the Else part (the call to "cancelAlert") doesn't work in either release or debug mode - unless I step through the code line by line. If I change the code to:

B4X:
'cDlg is a Custom Dialog
cDlg.ShowAsync(mName.Trim, "Close", "", alertText, LoadBitmap(File.DirAssets, "ic_info_outline_black_24dp.png"), True)
cDlg.SetSize(100%x, 405dip)
Wait For Dialog_Ready(pnl As Panel)
pnl.LoadLayout("popup")
Wait For Dialog_Result(res As Int)
If res = DialogResponse.NEGATIVE Then
    If alertText = "Set Alert" Then
        CallSub3(Starter, "setAlert", mIndex, mTimeLeft * 1000)
    Else
         CallSub2(Starter, "cancelAlert", mIndex)
    End If
End If

it works fine every time.

I am using B4A v8.10 BETA #0 - so not sure if it's related to that or whether it happens on older versions as well. Obviously the pause created by stepping through the code is helping, but I'm not sure why it fails when the If Else is inline.

- Colin.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tried to reproduce with code:
B4X:
Sub Activity_Click
   Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null, False)
   Wait For Msgbox_Result (Result As Int)
   If Result = DialogResponse.NEGATIVE Then
       If False Then CallSub(Starter, "Test1") Else CallSub(Starter, "Test2")
   End If
End Sub
It works properly.

Can you reproduce it in a small project?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I have the following piece of code in a sub in one of my apps:

B4X:
'cDlg is a Custom Dialog
cDlg.ShowAsync(mName.Trim, "Close", "", alertText, LoadBitmap(File.DirAssets, "ic_info_outline_black_24dp.png"), True)
cDlg.SetSize(100%x, 405dip)
Wait For Dialog_Ready(pnl As Panel)
pnl.LoadLayout("popup")
Wait For Dialog_Result(res As Int)
If res = DialogResponse.NEGATIVE Then
    If alertText = "Set Alert" Then CallSub3(Starter, "setAlert", mIndex, mTimeLeft * 1000) Else CallSub2(Starter, "cancelAlert", mIndex)
End If

The If part (the call to "setAlert") works fine every time, however the Else part (the call to "cancelAlert") doesn't work in either release or debug mode - unless I step through the code line by line. If I change the code to:

B4X:
'cDlg is a Custom Dialog
cDlg.ShowAsync(mName.Trim, "Close", "", alertText, LoadBitmap(File.DirAssets, "ic_info_outline_black_24dp.png"), True)
cDlg.SetSize(100%x, 405dip)
Wait For Dialog_Ready(pnl As Panel)
pnl.LoadLayout("popup")
Wait For Dialog_Result(res As Int)
If res = DialogResponse.NEGATIVE Then
    If alertText = "Set Alert" Then
        CallSub3(Starter, "setAlert", mIndex, mTimeLeft * 1000)
    Else
         CallSub2(Starter, "cancelAlert", mIndex)
    End If
End If

it works fine every time.

I am using B4A v8.10 BETA #0 - so not sure if it's related to that or whether it happens on older versions as well. Obviously the pause created by stepping through the code is helping, but I'm not sure why it fails when the If Else is inline.

- Colin.
B4A 8.10 beta? exists?
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
It's a very early beta that Erel sent me because I was having an issue with the Starter service in Android 8.x...

- Colin.
 
Upvote 0
Top