Bug? CallSub return value

SteveTerrell

Active Member
Licensed User
Longtime User
Version 3.2

I have the following code in Main

B4X:
Sub CallsubTarget As Int
    Return 1
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim i As Int

    i = CallSub(Me,"CallsubTarget")

This fails at runtime with and exception invalid double "null".

PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
java.lang.NumberFormatException: Invalid double: "null"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:269)
at java.lang.Double.parseDouble(Double.java:295)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:585)
at b4a.example.main._activity_create(main.java:305)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at b4a.example.main.afterFirstLayout(main.java:98)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

It also does not seem to run the CallsubTarget code (or at least fails to hit a breakpoint on the return line. Is the CallsubTarget optimised out?

There is a suggestion in some documentation that the first parameter for CallSub should be the module name (Main in this case) but CallSub(Main,"CallsubTarget") gives an compile error, me seems to be accepted by the compiler though.
 

SteveTerrell

Active Member
Licensed User
Longtime User
Why do you try to call a sub inside the same module using CallSub?

You can use directly:

i = CallsubTarget


I realise that, this is a simplified test case for a more complex arrangement which fails in the same way.

I believe it should have worked even in this unnecessary example.
 

SteveTerrell

Active Member
Licensed User
Longtime User
CallSu + CTRL + Spacebar <---- Help :)

To call a sub in the same module, you should provide an empty string as "component":

CallSub("", "CallsubTarget")


If you try it you will find it fails in the same way. The real problem appears to be the return object.

Even with Me replaced by "" it still does not hit a breakpoint in CallsubTarget

I may be wrong but i think the empty string is an option which can be used.
 

SteveTerrell

Active Member
Licensed User
Longtime User
Yes that fixed it, thanks.

The invalid double "null" fault report is a bit unhelpful, could the (wrong usage) situation be better detected and reported?
 
Top