Android Question Basics -- Strings, Objects and Types

Steve Piehl

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

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

Steve Piehl

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

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

 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
    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

B4X:
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 **
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Steve Piehl

Member
Licensed User
Longtime User
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…