CallSubDelayed2 + argument from EditText?

Penko

Active Member
Licensed User
Longtime User
Hello, consider the following two lines:

B4X:
'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.

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
I don't know but perhaps you should just use a variable, like
B4X:
dim vrt as int:vrt=txt123.text
and then call your sub using vrt instead of txt123.text? just a thought.
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
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:

B4X:
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

Penko

Active Member
Licensed User
Longtime User
@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

Roger Garstang

Well-Known Member
Licensed User
Longtime User
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

Ricky D

Well-Known Member
Licensed User
Longtime User
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

B4X:
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

Penko

Active Member
Licensed User
Longtime User
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

Roger Garstang

Well-Known Member
Licensed User
Longtime User
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

Penko

Active Member
Licensed User
Longtime User
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
Top