P Penko Active Member Licensed User Longtime User Jul 6, 2012 #1 Hello, consider the following two lines: Code: Copy 'CallSubDelayed2(aRecipesAddEdit, "loadDataByID", txt123.Text) CallSubDelayed2(aRecipesAddEdit, "loadDataByID", 3) With the first line, I get the following error: java.lang.Exception: Sub loaddatabyid signature does not match expected signature. Click to expand... If I leave the argument constant(3 in this example), everything is running like a charm. txt123.Text is defined and it has value. What's the reason for this weird behavior?
Hello, consider the following two lines: Code: Copy 'CallSubDelayed2(aRecipesAddEdit, "loadDataByID", txt123.Text) CallSubDelayed2(aRecipesAddEdit, "loadDataByID", 3) With the first line, I get the following error: java.lang.Exception: Sub loaddatabyid signature does not match expected signature. Click to expand... If I leave the argument constant(3 in this example), everything is running like a charm. txt123.Text is defined and it has value. What's the reason for this weird behavior?
mc73 Well-Known Member Licensed User Longtime User Jul 6, 2012 #2 I don't know but perhaps you should just use a variable, like Code: Copy dim vrt as int:vrt=txt123.text and then call your sub using vrt instead of txt123.text? just a thought. Upvote 0
I don't know but perhaps you should just use a variable, like Code: Copy dim vrt as int:vrt=txt123.text and then call your sub using vrt instead of txt123.text? just a thought.
margret Well-Known Member Licensed User Longtime User Jul 6, 2012 #3 Try calling it with this line. Code: Copy CallSubDelayed2(aRecipesAddEdit, "loadDataByID", (txt123.Text + 0)) Upvote 0
Try calling it with this line. Code: Copy CallSubDelayed2(aRecipesAddEdit, "loadDataByID", (txt123.Text + 0))
P Penko Active Member Licensed User Longtime User Jul 6, 2012 #4 Guys, thank you for the time spent, let me summarize the situation: Unfortunately, @marget's solution produces exactly the same error although it was the shortest one. It was yesterday at 2 AM when I got this error and had in mind to try with a function this morning. So, I tried: Code: Copy Sub getParam() Return txt123.Text End Sub ' this is just called in CallSubDelayed2's argument. The result is exactly the same error. @mc73 - it is only your suggestion from the above three, that works. I suppose Erel may throw some light on why is this happening. For now, we may use variables ensuring proper program execution. Thank you both once more! Upvote 0
Guys, thank you for the time spent, let me summarize the situation: Unfortunately, @marget's solution produces exactly the same error although it was the shortest one. It was yesterday at 2 AM when I got this error and had in mind to try with a function this morning. So, I tried: Code: Copy Sub getParam() Return txt123.Text End Sub ' this is just called in CallSubDelayed2's argument. The result is exactly the same error. @mc73 - it is only your suggestion from the above three, that works. I suppose Erel may throw some light on why is this happening. For now, we may use variables ensuring proper program execution. Thank you both once more!
margret Well-Known Member Licensed User Longtime User Jul 6, 2012 #5 Please try your sub like this. If this don't work the auto casting is not working like the previous versions. Code: Copy Sub getParam() Return 0 + txt123.Text End Sub Upvote 0
Please try your sub like this. If this don't work the auto casting is not working like the previous versions. Code: Copy Sub getParam() Return 0 + txt123.Text End Sub
R Roger Garstang Well-Known Member Licensed User Longtime User Jul 6, 2012 #6 Sub getParam as int Either way does the same thing, creates a temp int that auto casts to the correct type. What would be really nice is if it worked like other languages with: CallSubDelayed2(aRecipesAddEdit, "loadDataByID", (int)txt123.Text) Some type of numeric parser or a string.val function would be nice too. Upvote 0
Sub getParam as int Either way does the same thing, creates a temp int that auto casts to the correct type. What would be really nice is if it worked like other languages with: CallSubDelayed2(aRecipesAddEdit, "loadDataByID", (int)txt123.Text) Some type of numeric parser or a string.val function would be nice too.
P Penko Active Member Licensed User Longtime User Jul 6, 2012 #7 @margret, unfortunately that didn't work too. @Roger, that would be really nice but basically, as far as I know, this is why there is auto-casting. There is just some nasty compiler error(java code generator) here producing the issues. At least we have the variable solution which works as expected. Upvote 0
@margret, unfortunately that didn't work too. @Roger, that would be really nice but basically, as far as I know, this is why there is auto-casting. There is just some nasty compiler error(java code generator) here producing the issues. At least we have the variable solution which works as expected.
Erel B4X founder Staff member Licensed User Longtime User Jul 8, 2012 #8 Margret code should be: Code: Copy Sub getParam() As Int Return txt123.Text End Sub When you use CallSub or CallSubDelayed the parameters are passed as is to the target sub. The compiler isn't able to cast them. You can either change the target sub parameter type to string or use a variable to explicitly set the type. Upvote 0
Margret code should be: Code: Copy Sub getParam() As Int Return txt123.Text End Sub When you use CallSub or CallSubDelayed the parameters are passed as is to the target sub. The compiler isn't able to cast them. You can either change the target sub parameter type to string or use a variable to explicitly set the type.
P Penko Active Member Licensed User Longtime User Jul 8, 2012 #9 Erel, thanks. This throws light on what the problem is. Sent from my HTC Desire using Tapatalk Upvote 0
margret Well-Known Member Licensed User Longtime User Jul 8, 2012 #10 Thanks Erel, Agraham covered this as well on another subject yesterday. This does explain many things I have run into. Always great to learn more! Thanks again for the information. Upvote 0
Thanks Erel, Agraham covered this as well on another subject yesterday. This does explain many things I have run into. Always great to learn more! Thanks again for the information.
R Roger Garstang Well-Known Member Licensed User Longtime User Jul 9, 2012 #11 First line of my post showed the missing "as int" and then explained what happens, probably should have put it in a code block. Conversion stuff like this would make for a good Class. Then it isn't just a function for converting one variable, but you could pass it a value and then it would return what you want for anything passed. Static Classes for it would be even better...hopefully something like them are added in the future. Upvote 0
First line of my post showed the missing "as int" and then explained what happens, probably should have put it in a code block. Conversion stuff like this would make for a good Class. Then it isn't just a function for converting one variable, but you could pass it a value and then it would return what you want for anything passed. Static Classes for it would be even better...hopefully something like them are added in the future.
Ricky D Well-Known Member Licensed User Longtime User Jul 10, 2012 #12 Roger, code modules can be used to have a static class. I have a utils module - u and use it throughout my apps. so I can do stuff like Code: Copy Sub bShiftDate_Click u.DateName = "ShiftDate" u.TimeValue = DateTime.DateParse(ShiftDate) StartActivity(Kalendar) End Sub 'Kalendar will set DateReturned if I change the date Sub Activity_Resume If u.DateName="ShiftDate" Then If u.DateReturned>0 Then DateTime.DateFormat = "yyyyMMdd" ShiftDate = DateTime.Date(u.DateReturned) lShiftDate = u.DateLongFormat(ShiftDate) 'display it as Mon, 3-Jun-2012 End if End if End Sub In this code snippet my u module contains properties like DateName, TimeValue & DateReturned as well as methods like DateLongFormat Just add a code module and away you go. No need to initialize it before using it. regards, Ricky Upvote 0
Roger, code modules can be used to have a static class. I have a utils module - u and use it throughout my apps. so I can do stuff like Code: Copy Sub bShiftDate_Click u.DateName = "ShiftDate" u.TimeValue = DateTime.DateParse(ShiftDate) StartActivity(Kalendar) End Sub 'Kalendar will set DateReturned if I change the date Sub Activity_Resume If u.DateName="ShiftDate" Then If u.DateReturned>0 Then DateTime.DateFormat = "yyyyMMdd" ShiftDate = DateTime.Date(u.DateReturned) lShiftDate = u.DateLongFormat(ShiftDate) 'display it as Mon, 3-Jun-2012 End if End if End Sub In this code snippet my u module contains properties like DateName, TimeValue & DateReturned as well as methods like DateLongFormat Just add a code module and away you go. No need to initialize it before using it. regards, Ricky
P Penko Active Member Licensed User Longtime User Jul 10, 2012 #13 Guys, before version 2.0, I was doing it with code modules. I don't know if you are gonna believe it but currently I don't have a single process global variable if we do not take into account some AppSettings variables which are static at all and maybe the SQLL object. Everything else is pretty much transmitted via arguments and it is the callsubdelayed Sub that changed the way I code. Now, everything is simply data classes which store information about my objects and this information is being relayed in accordance with the needs. Erel is just making miracles with each new version. B4A is still this year's my best software investment. Sent from my HTC Desire using Tapatalk Upvote 0
Guys, before version 2.0, I was doing it with code modules. I don't know if you are gonna believe it but currently I don't have a single process global variable if we do not take into account some AppSettings variables which are static at all and maybe the SQLL object. Everything else is pretty much transmitted via arguments and it is the callsubdelayed Sub that changed the way I code. Now, everything is simply data classes which store information about my objects and this information is being relayed in accordance with the needs. Erel is just making miracles with each new version. B4A is still this year's my best software investment. Sent from my HTC Desire using Tapatalk
R Roger Garstang Well-Known Member Licensed User Longtime User Jul 10, 2012 #14 Cool, that is the best way to do it. It is often hard making some things work without Globals...especially in Android where a simple rotation kills an activity and all its variables. I was reading somewhere in an android Forum where you can setup your app to not do the pause/kill/resume cycle stuff on rotate with a certain manifest value or something. It would be really cool if B4A just let us redraw and didn't kill everything on rotate. Without globals you have to save data to file which is slower and not much different than using globals in the first place. Upvote 0
Cool, that is the best way to do it. It is often hard making some things work without Globals...especially in Android where a simple rotation kills an activity and all its variables. I was reading somewhere in an android Forum where you can setup your app to not do the pause/kill/resume cycle stuff on rotate with a certain manifest value or something. It would be really cool if B4A just let us redraw and didn't kill everything on rotate. Without globals you have to save data to file which is slower and not much different than using globals in the first place.
P Penko Active Member Licensed User Longtime User Jul 10, 2012 #15 You may also consder the option to use only one screen mode. Thus there is no problem. Of course, this is unacceptable in most cases but you can do it for activities which work better(e.g in landscape) and do not in portrait. What you are saying is interesting but it may be hardly possible. I am far from an expert, the others may throw more light. Sent from my HTC Desire using Tapatalk Upvote 0
You may also consder the option to use only one screen mode. Thus there is no problem. Of course, this is unacceptable in most cases but you can do it for activities which work better(e.g in landscape) and do not in portrait. What you are saying is interesting but it may be hardly possible. I am far from an expert, the others may throw more light. Sent from my HTC Desire using Tapatalk