Steve Piehl Member Licensed User Longtime User Nov 27, 2016 #1 I have been playing with this for quite awhile and not sure how to use the CallSubDelayedPlus2 routine. I have loaded the CallSubUtils class module and I am attempting to call a subroutine in the same module I am in (main). I have already tried to review the tutorial on variables and objects and I am just not understanding something. I don't understand enough about Objects versus Strings. How do you convert from object to a string and vice versa? My original subroutine "SendJobToServer" was setup to receive an arg as a "String" arg...not an "Object". The CallSubDelayedPlus2 routine requires that args be sent as Objects. I changed the arg to look for an object...but that doesn't seem to work. In the code snippet below, I attempt to pass the String arg "StatusUpdate" as an object to be used in the subroutine. Also I need this arg "JobName" to be a string. Do I have to use stringbuilder to get around the need for a string after passing it as an object? How do I pass it as an object? Code: Copy Sub SendJobtoServer (JobName As Object) Log("SendJobtoServer, Job= "& JobName) Dim j As HttpJob j.Initialize(JobName, Me) j.Download(ServerLink & "/" & JobName) If JobName = "StatusUpdate" Then ProgressDialogShow("Updating System Status...") Else ProgressDialogShow("Downloading report...") End If End Sub Sub SetSystem Status ... Dim Job2Send As Object Job2Send="StatusUpdate" Starter.csu.CallSubDelayedPlus2(Me,"SendJobtoServer",2000,Job2Send) '<---error object End Sub Any help is appreciated.
I have been playing with this for quite awhile and not sure how to use the CallSubDelayedPlus2 routine. I have loaded the CallSubUtils class module and I am attempting to call a subroutine in the same module I am in (main). I have already tried to review the tutorial on variables and objects and I am just not understanding something. I don't understand enough about Objects versus Strings. How do you convert from object to a string and vice versa? My original subroutine "SendJobToServer" was setup to receive an arg as a "String" arg...not an "Object". The CallSubDelayedPlus2 routine requires that args be sent as Objects. I changed the arg to look for an object...but that doesn't seem to work. In the code snippet below, I attempt to pass the String arg "StatusUpdate" as an object to be used in the subroutine. Also I need this arg "JobName" to be a string. Do I have to use stringbuilder to get around the need for a string after passing it as an object? How do I pass it as an object? Code: Copy Sub SendJobtoServer (JobName As Object) Log("SendJobtoServer, Job= "& JobName) Dim j As HttpJob j.Initialize(JobName, Me) j.Download(ServerLink & "/" & JobName) If JobName = "StatusUpdate" Then ProgressDialogShow("Updating System Status...") Else ProgressDialogShow("Downloading report...") End If End Sub Sub SetSystem Status ... Dim Job2Send As Object Job2Send="StatusUpdate" Starter.csu.CallSubDelayedPlus2(Me,"SendJobtoServer",2000,Job2Send) '<---error object End Sub Any help is appreciated.
Erel B4X founder Staff member Licensed User Longtime User Nov 28, 2016 #2 Code: Copy Starter.csu.CallSubDelayedPlus2(Me, "SendJobTo_Server", 2000, Array ("StatusUpdate")) Sub SendJobTo_Server (Name As String) 'tip: add an underscore to prevent the obfuscator from obfuscating the sub name ... End Sub Upvote 0
Code: Copy Starter.csu.CallSubDelayedPlus2(Me, "SendJobTo_Server", 2000, Array ("StatusUpdate")) Sub SendJobTo_Server (Name As String) 'tip: add an underscore to prevent the obfuscator from obfuscating the sub name ... End Sub
Steve Piehl Member Licensed User Longtime User Nov 28, 2016 #3 Erel -- thanks for your reply. I made the changes you suggested. I am still generating an error...now it appears that I can pass the variable to the SendJobTo_Server routine...but this routine is generating a similar error on the j.initialize line. Code: Copy Sub SendJobTo_Server (JobName As String) Log("SendJobtoServer, Job= "& JobName) Dim j As HttpJob j.Initialize(JobName, Me) '<---ERROR occurs here now (line 113) j.Download(ServerLink & "/" & JobName) If JobName = "StatusUpdate" Then ProgressDialogShow("Updating System Status...") Else ProgressDialogShow("Downloading report...") End If End Sub Here is the output from the debug log: Code: Copy SendJobtoServer, Job= [Ljava.lang.Object;@6eb6977 Error occurred on line: 113 (Main) java.lang.IllegalArgumentException: method anywheresoftware.b4a.samples.httputils2.httpjob._initialize argument 2 has type java.lang.String, got java.lang.Object[] at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at anywheresoftware.b4a.BA$2.run(BA.java:328) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7224) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Click to expand... Upvote 0
Erel -- thanks for your reply. I made the changes you suggested. I am still generating an error...now it appears that I can pass the variable to the SendJobTo_Server routine...but this routine is generating a similar error on the j.initialize line. Code: Copy Sub SendJobTo_Server (JobName As String) Log("SendJobtoServer, Job= "& JobName) Dim j As HttpJob j.Initialize(JobName, Me) '<---ERROR occurs here now (line 113) j.Download(ServerLink & "/" & JobName) If JobName = "StatusUpdate" Then ProgressDialogShow("Updating System Status...") Else ProgressDialogShow("Downloading report...") End If End Sub Here is the output from the debug log: Code: Copy SendJobtoServer, Job= [Ljava.lang.Object;@6eb6977 Error occurred on line: 113 (Main) java.lang.IllegalArgumentException: method anywheresoftware.b4a.samples.httputils2.httpjob._initialize argument 2 has type java.lang.String, got java.lang.Object[] at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at anywheresoftware.b4a.BA$2.run(BA.java:328) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7224) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Click to expand...
KMatle Expert Licensed User Longtime User Nov 29, 2016 #4 Clear: You send an array. Jobname must be a string. So just convert it back to a string... Upvote 0
DonManfred Expert Licensed User Longtime User Nov 29, 2016 #5 Code: Copy Starter.csu.CallSubDelayedPlus3(Me, "SendJobTo_Server", 2000, Array As String("StatusUpdate")) Sub SendJobTo_Server (param() As String) Dim jobname As String = param(0) Log("SendJobtoServer, Job= "& jobname) Dim j As HttpJob j.Initialize(jobname, Me) '<---ERROR occurs here now (line 113): occurs no longer 'j.Download(ServerLink & "/" & JobName) 'If JobName = "StatusUpdate" Then ' ProgressDialogShow("Updating System Status...") 'Else ' ProgressDialogShow("Downloading report...") 'End If End Sub And the method you need to add to the CallSubUtils Class Code: Copy Public Sub CallSubDelayedPlus3(Module As Object, SubName As String, Delay As Int, Arg() As String) PlusImpl(Module, SubName, Delay, Arg, True) End Sub ** Service (starter) Create ** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** SendJobtoServer, Job= StatusUpdate ** Activity (main) Pause, UserClosed = false ** ** Activity (main) Resume ** Click to expand... Upvote 0
Code: Copy Starter.csu.CallSubDelayedPlus3(Me, "SendJobTo_Server", 2000, Array As String("StatusUpdate")) Sub SendJobTo_Server (param() As String) Dim jobname As String = param(0) Log("SendJobtoServer, Job= "& jobname) Dim j As HttpJob j.Initialize(jobname, Me) '<---ERROR occurs here now (line 113): occurs no longer 'j.Download(ServerLink & "/" & JobName) 'If JobName = "StatusUpdate" Then ' ProgressDialogShow("Updating System Status...") 'Else ' ProgressDialogShow("Downloading report...") 'End If End Sub And the method you need to add to the CallSubUtils Class Code: Copy Public Sub CallSubDelayedPlus3(Module As Object, SubName As String, Delay As Int, Arg() As String) PlusImpl(Module, SubName, Delay, Arg, True) End Sub ** Service (starter) Create ** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** ** Activity (main) Resume ** SendJobtoServer, Job= StatusUpdate ** Activity (main) Pause, UserClosed = false ** ** Activity (main) Resume ** Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Nov 29, 2016 #6 My code was wrong. See the tutorial: https://www.b4x.com/android/forum/threads/b4x-callsubplus-callsub-with-explicit-delay.60877/#content It should be: Code: Copy Starter.csu.CallSubDelayedPlus2(Me, "SendJobTo_Server", 2000, Array ("StatusUpdate")) Sub SendJobTo_Server (Args() As Object) 'tip: add an underscore to prevent the obfuscator from obfuscating the sub name Dim Name As String = Args(0) End Sub Upvote 0
My code was wrong. See the tutorial: https://www.b4x.com/android/forum/threads/b4x-callsubplus-callsub-with-explicit-delay.60877/#content It should be: Code: Copy Starter.csu.CallSubDelayedPlus2(Me, "SendJobTo_Server", 2000, Array ("StatusUpdate")) Sub SendJobTo_Server (Args() As Object) 'tip: add an underscore to prevent the obfuscator from obfuscating the sub name Dim Name As String = Args(0) End Sub
Steve Piehl Member Licensed User Longtime User Nov 29, 2016 #7 Thank you to everyone for your replies. I am beginning to understand how to convert objects to strings and vice versa. I was missing the idea that you can pass an arg to a subroutine as an object and then re-define that object/item to another datatype on-the-fly. This is very useful information. Thanks again! Upvote 0
Thank you to everyone for your replies. I am beginning to understand how to convert objects to strings and vice versa. I was missing the idea that you can pass an arg to a subroutine as an object and then re-define that object/item to another datatype on-the-fly. This is very useful information. Thanks again!