Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #1 I have been replacing all the Msgbox & Msgbox2 calls in my apps with MsgboxAsync & Msgbox2Async calls. After reading Erel's tutorial, I came to the conclusion that for a MsgboxAsync call, there is not necessarily a requirement to use a Wait For Msgbox_Result if there isn't any code after the dialog that you want to hold off executing until the dialog has been dismissed. So, with this in mind I implemented the following sub: Code: Sub mnuAbout_Click Private sMsg As String sMsg = "myPets v" & Get_Version & CRLF & CRLF & _ "Copyright (c) 2015-2017 Computersmith" & CRLF & CRLF & _ "Icons created by Freepik (www.freepik.com)" MsgboxAsync(sMsg, "About myPets") End Sub This sub is called from an Activity menu item, so is run pretty much in isolation - therefore I figured that the Wait For would be not required - but in testing, I discovered that it will crash every time when the OK button is tapped. This is the error I get in the debug log: An error occurred: (Line: 1062) End Sub java.lang.Exception: Sub msgbox_result signature does not match expected signature. public static void com.airlinemates.mypets.main_subs_1._msgbox_result() throws java.lang.Exception Click to expand... If I put in a Wait For, it no longer crashes. Any ideas why? - Colin.
I have been replacing all the Msgbox & Msgbox2 calls in my apps with MsgboxAsync & Msgbox2Async calls. After reading Erel's tutorial, I came to the conclusion that for a MsgboxAsync call, there is not necessarily a requirement to use a Wait For Msgbox_Result if there isn't any code after the dialog that you want to hold off executing until the dialog has been dismissed. So, with this in mind I implemented the following sub: Code: Sub mnuAbout_Click Private sMsg As String sMsg = "myPets v" & Get_Version & CRLF & CRLF & _ "Copyright (c) 2015-2017 Computersmith" & CRLF & CRLF & _ "Icons created by Freepik (www.freepik.com)" MsgboxAsync(sMsg, "About myPets") End Sub This sub is called from an Activity menu item, so is run pretty much in isolation - therefore I figured that the Wait For would be not required - but in testing, I discovered that it will crash every time when the OK button is tapped. This is the error I get in the debug log: An error occurred: (Line: 1062) End Sub java.lang.Exception: Sub msgbox_result signature does not match expected signature. public static void com.airlinemates.mypets.main_subs_1._msgbox_result() throws java.lang.Exception Click to expand... If I put in a Wait For, it no longer crashes. Any ideas why? - Colin.
DonManfred Expert Licensed User Longtime User Jul 12, 2017 #2 How does you event sub signature (msgbox_result) look like? If you dont use wait for then you need to have the event defined.... Upvote 0
How does you event sub signature (msgbox_result) look like? If you dont use wait for then you need to have the event defined....
Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #3 DonManfred said: How does you event sub signature (msgbox_result) look like? If you dont use wait for then you need to have the event defined.... Click to expand... Oh - ok, I must have missed that in the tutorial. I don't have it defined at all. Maybe that's the problem. What is the signature supposed to look like? - Colin. Upvote 0
DonManfred said: How does you event sub signature (msgbox_result) look like? If you dont use wait for then you need to have the event defined.... Click to expand... Oh - ok, I must have missed that in the tutorial. I don't have it defined at all. Maybe that's the problem. What is the signature supposed to look like? - Colin.
DonManfred Expert Licensed User Longtime User Jul 12, 2017 #4 Computersmith64 said: What is the signature supposed to look like? Click to expand... Based on the code in the tutorial about async dialogs Code: Msgbox2Async("Delete?", "Title", "Yes", "Cancel", "No", Null, False) Wait For Msgbox_Result (Result As Int) If Result = DialogResponse.POSITIVE Then '... End If i would guess Code: sub Msgbox_Result (Result As Int) end sub But: why not use the wait for to react on the result in the same sub? Upvote 0
Computersmith64 said: What is the signature supposed to look like? Click to expand... Based on the code in the tutorial about async dialogs Code: Msgbox2Async("Delete?", "Title", "Yes", "Cancel", "No", Null, False) Wait For Msgbox_Result (Result As Int) If Result = DialogResponse.POSITIVE Then '... End If i would guess Code: sub Msgbox_Result (Result As Int) end sub But: why not use the wait for to react on the result in the same sub?
Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #5 DonManfred said: Based on the code in the tutorial about async dialogs Code: Msgbox2Async("Delete?", "Title", "Yes", "Cancel", "No", Null, False) Wait For Msgbox_Result (Result As Int) If Result = DialogResponse.POSITIVE Then '... End If i would guess Code: sub Msgbox_Result (Result As Int) end sub Click to expand... Yeah - thanks, I figured it out in the meantime.... That seems to have resolved the issue. I guess I can just put a Wait For in too, but it seems redundant if it's the last line of code in the sub. - Colin. Upvote 0
DonManfred said: Based on the code in the tutorial about async dialogs Code: Msgbox2Async("Delete?", "Title", "Yes", "Cancel", "No", Null, False) Wait For Msgbox_Result (Result As Int) If Result = DialogResponse.POSITIVE Then '... End If i would guess Code: sub Msgbox_Result (Result As Int) end sub Click to expand... Yeah - thanks, I figured it out in the meantime.... That seems to have resolved the issue. I guess I can just put a Wait For in too, but it seems redundant if it's the last line of code in the sub. - Colin.
Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #6 DonManfred said: Based on the code in the tutorial about async dialogs But: why not use the wait for to react on the result in the same sub? Click to expand... That's the thing though - there's no reason to use a Wait For because there's nothing to react to & no code to execute after the user taps the OK button in the dialog. Therefore it seems redundant (& inefficient) to have the sub resume when there's nothing for it to do. Or maybe I'm just not understanding the implementation correctly.... - Colin. Upvote 0
DonManfred said: Based on the code in the tutorial about async dialogs But: why not use the wait for to react on the result in the same sub? Click to expand... That's the thing though - there's no reason to use a Wait For because there's nothing to react to & no code to execute after the user taps the OK button in the dialog. Therefore it seems redundant (& inefficient) to have the sub resume when there's nothing for it to do. Or maybe I'm just not understanding the implementation correctly.... - Colin.
Erel B4X founder Staff member Licensed User Longtime User Jul 12, 2017 #7 You are correct. There is no reason to use Wait For here (the code example also don't include a Wait For). Is this code inside a class? Upvote 0
You are correct. There is no reason to use Wait For here (the code example also don't include a Wait For). Is this code inside a class?
Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #8 Erel said: You are correct. There is no reason to use Wait For here (the code example also don't include a Wait For). Is this code inside a class? Click to expand... No - it's inside my Main activity. So are you saying that I also don't need an empty implementation of the Msgbox_Result method? - Colin. Upvote 0
Erel said: You are correct. There is no reason to use Wait For here (the code example also don't include a Wait For). Is this code inside a class? Click to expand... No - it's inside my Main activity. So are you saying that I also don't need an empty implementation of the Msgbox_Result method? - Colin.
Erel B4X founder Staff member Licensed User Longtime User Jul 12, 2017 #9 It looks like a bug. Can you reproduce it in a small project? Upvote 0
Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #10 Erel said: It looks like a bug. Can you reproduce it in a small project? Click to expand... Hi Erel, I've attached a project that will crash - however I'm thinking that I might be causing the issue by having a MsgboxAsync with a Wait For Msgbox_Result in the Activity_Create sub. Is that allowed? - Colin. Attachments msgboxcrash.zip msgboxcrash.zip 7.7 KB · Views: 470 Upvote 0
Erel said: It looks like a bug. Can you reproduce it in a small project? Click to expand... Hi Erel, I've attached a project that will crash - however I'm thinking that I might be causing the issue by having a MsgboxAsync with a Wait For Msgbox_Result in the Activity_Create sub. Is that allowed? - Colin.
DonManfred Expert Licensed User Longtime User Jul 12, 2017 #11 Computersmith64 said: Is that allowed? Click to expand... i would guess no. It should be called after activity_resume is raised Upvote 0
Computersmith64 said: Is that allowed? Click to expand... i would guess no. It should be called after activity_resume is raised
Computersmith64 Well-Known Member Licensed User Longtime User Jul 12, 2017 #12 DonManfred said: i would guess no. It should be called after activity_resume is raised Click to expand... I've always had Msgbox calls in Activity_Create in this particular app & they've never caused me issues (that I'm aware of) until I changed them to Async calls. In fact, even the Async call in Activity_Create isn't triggering the crash - it's the MsgboxAsync call in the menu_Click event that's doing it. Granted, it doesn't crash if the call in Activity_Create isn't there, but I'd like to understand why this causes the issue later on - because it only happens when I don't have either a Wait For or a Msgbox_Result declared for the later MsgboxAsync call. - Colin. Upvote 0
DonManfred said: i would guess no. It should be called after activity_resume is raised Click to expand... I've always had Msgbox calls in Activity_Create in this particular app & they've never caused me issues (that I'm aware of) until I changed them to Async calls. In fact, even the Async call in Activity_Create isn't triggering the crash - it's the MsgboxAsync call in the menu_Click event that's doing it. Granted, it doesn't crash if the call in Activity_Create isn't there, but I'd like to understand why this causes the issue later on - because it only happens when I don't have either a Wait For or a Msgbox_Result declared for the later MsgboxAsync call. - Colin.
Computersmith64 Well-Known Member Licensed User Longtime User Jul 13, 2017 #13 So this is interesting. Based on DonManfred's comments, I moved the first MsgboxAsync call out of Activity_Create & into its own sub that is called by a menu item. So now I have 2 menu items ("Show First Dialog" & "Show Second Dialog") & 2 separate subs linked to them that call MsgboxAsync. The first one uses a Wait For Msgbox_Result & the second one doesn't. The interesting part is that regardless of whether or not I show the first dialog, the second dialog always crashes when I tap the OK button. So just having that first call in the activity code is enough to make any subsequent call without a Wait For crash. This definitely seems like a bug doesn't it @Erel? Project is attached. - Colin. Attachments msgboxcrash2.zip msgboxcrash2.zip 7.4 KB · Views: 466 Upvote 0
So this is interesting. Based on DonManfred's comments, I moved the first MsgboxAsync call out of Activity_Create & into its own sub that is called by a menu item. So now I have 2 menu items ("Show First Dialog" & "Show Second Dialog") & 2 separate subs linked to them that call MsgboxAsync. The first one uses a Wait For Msgbox_Result & the second one doesn't. The interesting part is that regardless of whether or not I show the first dialog, the second dialog always crashes when I tap the OK button. So just having that first call in the activity code is enough to make any subsequent call without a Wait For crash. This definitely seems like a bug doesn't it @Erel? Project is attached. - Colin.
Erel B4X founder Staff member Licensed User Longtime User Jul 13, 2017 #14 Tip: use smart string literals for multiline text: Code: sMsg = $"myPets v${Get_Version} Copyright (c) 2015-2017 Computersmith Icons created by Freepik (www.freepik.com)"$ About the crash, the Wait For signature is incorrect. It should be: Code: Wait For Msgbox_Result (result As Int) Upvote 0
Tip: use smart string literals for multiline text: Code: sMsg = $"myPets v${Get_Version} Copyright (c) 2015-2017 Computersmith Icons created by Freepik (www.freepik.com)"$ About the crash, the Wait For signature is incorrect. It should be: Code: Wait For Msgbox_Result (result As Int)
Computersmith64 Well-Known Member Licensed User Longtime User Jul 13, 2017 #15 Erel said: Tip: use smart string literals for multiline text: Code: sMsg = $"myPets v${Get_Version} Copyright (c) 2015-2017 Computersmith Icons created by Freepik (www.freepik.com)"$ Click to expand... Thanks - actually I have been using them for a while. I just haven't updated all of the strings in this app yet. About the crash, the Wait For signature is incorrect. It should be: Code: Wait For Msgbox_Result (result As Int) Click to expand... Oh - right, of course. Dumb rookie mistake on my part. Weird though that it doesn't actually trigger an error unless there is another call in the same module that doesn't use a Wait For at all. Anyway, I retested it with the correct signature on call 1 & no Wait For on call 2, as well as without it on both calls & it all seems to work ok - so thanks! - Colin. Upvote 0
Erel said: Tip: use smart string literals for multiline text: Code: sMsg = $"myPets v${Get_Version} Copyright (c) 2015-2017 Computersmith Icons created by Freepik (www.freepik.com)"$ Click to expand... Thanks - actually I have been using them for a while. I just haven't updated all of the strings in this app yet. About the crash, the Wait For signature is incorrect. It should be: Code: Wait For Msgbox_Result (result As Int) Click to expand... Oh - right, of course. Dumb rookie mistake on my part. Weird though that it doesn't actually trigger an error unless there is another call in the same module that doesn't use a Wait For at all. Anyway, I retested it with the correct signature on call 1 & no Wait For on call 2, as well as without it on both calls & it all seems to work ok - so thanks! - Colin.
ilan Expert Licensed User Longtime User Jul 13, 2017 #16 Erel said: Tip: use smart string literals for multiline text: Code: sMsg = $"myPets v${Get_Version} Copyright (c) 2015-2017 Computersmith Icons created by Freepik (www.freepik.com)"$ About the crash, the Wait For signature is incorrect. It should be: Code: Wait For Msgbox_Result (result As Int) Click to expand... But if he only wants to use a simple msgbox without a result handler why does he needs a wait for call? I dont see any reason for a crash in the code posted in post #1. Its a simple msgbox and not msgbox2!! Upvote 0
Erel said: Tip: use smart string literals for multiline text: Code: sMsg = $"myPets v${Get_Version} Copyright (c) 2015-2017 Computersmith Icons created by Freepik (www.freepik.com)"$ About the crash, the Wait For signature is incorrect. It should be: Code: Wait For Msgbox_Result (result As Int) Click to expand... But if he only wants to use a simple msgbox without a result handler why does he needs a wait for call? I dont see any reason for a crash in the code posted in post #1. Its a simple msgbox and not msgbox2!!
Erel B4X founder Staff member Licensed User Longtime User Jul 13, 2017 #17 ilan said: But if he only wants to use a simple msgbox without a result handler why does he needs a wait for call? Click to expand... Wait For is indeed not needed (you can also see that there is no Wait For in the code example). The code in the first post by itself will not cause any error. Upvote 0
ilan said: But if he only wants to use a simple msgbox without a result handler why does he needs a wait for call? Click to expand... Wait For is indeed not needed (you can also see that there is no Wait For in the code example). The code in the first post by itself will not cause any error.