Android Question [Solved] Can't call CallSubDelayed2 with Variable?

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I have this code that raised an error
B4X:
Sub Test(RowId)
    CallSubDelayed2(CallFrom, SubToCall,RowId)
    Activity.Finish   
End Sub

Change the code to this
B4X:
Sub Test(RowId)
    CallSubDelayed2(CallFrom, "MySub",RowId)
    Activity.Finish  
End Sub

Fix the error. It is a bug or a normal behavior?
 

DonManfred

Expert
Licensed User
Longtime User
It seems to be a normal behaviour that you dont post the error you got.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
It seems to be a normal behavior that the error if not the issue here, so no need to post it, just simple question should it raised an error or not.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have tried it, it didn't work.

The error is "Sub mysub doesn't found."

mysub in the log is in lower capital, actual Sub name is MySub.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
try
B4X:
Sub Test(RowId)
    CallSubDelayed2(CallFrom, "mysub",RowId)
    Activity.Finish
End Sub

This will work, but this
B4X:
Sub Test(RowId)
    Private SubToCall as String
    SubToCall = "mysub"
    CallSubDelayed2(CallFrom, SubToCall ,RowId)
    Activity.Finish
End Sub
Doesn't works
java.lang.Exception: Sub mysub was not found.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Here are the code to call a sub in other activity
B4X:
Sub bbBatch_Clicked
    Private m As Map
    m.Initialize
    m.Put("CallFrom",Me)
    m.Put("SubToCall","MySub")
    CallSubDelayed2(ModSearchFrmN, "ShowData",m)
End Sub

And here are the codes from module ModSearchFrmN
B4X:
Sub Globals
  Private CallFrom As Object
   Private SubToCall As String
End Sub

Sub ShowData(Params As Map)
   CallFrom    = Params.Get("CallFrom")
   SubToCall    = Params.Get("SubToCall")
End Sub

Sub Test(RowId As Int)
    CallSubDelayed2(CallFrom, SubToCall,RowId) 'this is the error line
    Activity.Finish 
End Sub

Your second code should work.
Check if you have a module named CallFrom (CallFrom? Module to call!) and that this module has a routine named mysub.
There is no module named CallFrom

Hace you tried with smart string literal. ---> $""${SubtoCall}""$?

CallSubDelayed2(CallFrom, $""${SubToCall}""$,RowId) -> didn't work either.

java.lang.Exception: Sub "mysub" was not found.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
With "module" I meant: Activity module or Code module or Service module.

See the CallSubDelayed2 parameters; the first one must be the "module" which contains the routine to call.
There is no activity / service module with that name, CallFrom.
CallFrom is just an Object variable.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
My 50cts : the obfuscation ? Adding an underscore in the sub's name ?
You were right :)

Change the codes into like this solved the problem
B4X:
Sub bbBatch_Clicked
    Private m As Map
    m.Initialize
    m.Put("CallFrom",Me)
    m.Put("SubToCall","My_Sub") 'change Sub Name from MySub to My_Sub
    CallSubDelayed2(ModSearchFrmN, "ShowData",m)
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Change the code to this
Sub Test(RowId)
CallSubDelayed2(CallFrom,
"MySub",RowId)
Activity.Finish
End Sub
Fix the error.


Change the codes into like this solved the problem
Sub bbBatch_Clicked
Private m As Map
m.Initialize
m.Put(
"CallFrom",Me)
m.Put(
"SubToCall","My_Sub") 'change Sub Name from MySub to My_Sub
CallSubDelayed2(ModSearchFrmN, "ShowData",m)
End Sub


???
 
Upvote 0
Top