Android Question [Solved] Job with wait for into a class

ALBRECHT

Active Member
Licensed User
Hello,

I have a lot of sub routines that execute some poststrings actions with an ASP API.

So i have put the whole in a separate Code Module , like for example sending email directly via the API (its more simpler and lighter for the app) :

B4X:
Sub SendAnEmail(QSTT As String, QSMESS As String, QSNAME As String, QSMAIL As String, QSFOOT As String, QSSUBJ As String)
    Dim jobsm As HttpJob
    Dim Params As String
    Params = "QSTT=" & QSTT & "&QSMESS=" & QSMESS & "&QSNAME=" & QSNAME & "&QSMAIL=" & QSMAIL & "&QSFOOT=" & QSFOOT & "&QSSUBJ=" & QSSUBJ
    jobsm.Initialize("SendEmail",Main)
    jobsm.PostString(Main.BoWebSite & "/Asp/SendMail.asp", Params)
'    Wait For (jobsm) JobDone(jobsm As HttpJob)
    If jobsm.Success Then
        Log(jobsm.GetString)
    End If
    jobsm.Release
End Sub
But, in that case, as i can't use a "wait for" in a static module ( to receive the return event )

i have to check directly the success value.

will i receive a prospective different behavior (without the "wait for" line ) of my app when i use that simple routine ?

Regards
Michel
 

ALBRECHT

Active Member
Licensed User
Ok thanks : into a class, it works great, and the mail is sending,
but no way to log the result on the 2 last lines :
B4X:
    Log(jobsm.GetString)
    Return result

Calling by Main :
B4X:
Dim SDM As SDMail
Dim resSDMail As ResumableSub
SDM.Initialize("ATITLE...", "THEMESSAGE ...", dbmap.get("AppUserName"), dbmap.get("AppUserMail"), "TheFooter", "Confirmation User Account")
resSDMail = SDM.SendAnEmail
SDMail class :
B4X:
Sub Class_Globals
    Private QSTT, QSMESS, QSNAME, QSMAIL, QSFOOT, QSSUBJ As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (aQSTT As String, aQSMESS As String, aQSNAME As String, aQSMAIL As String, aQSFOOT As String, aQSSUBJ As String)
    QSTT = aQSTT
    QSMESS = aQSMESS
    QSNAME = aQSNAME
    QSMAIL = aQSMAIL
    QSFOOT = aQSFOOT
    QSSUBJ = aQSSUBJ
End Sub

Public Sub SendAnEmail As ResumableSub
    Dim jobsm As HttpJob
    Dim Params As String
    Dim result As String
    Params = "QSTT=" & QSTT & "&QSMESS=" & QSMESS & "&QSNAME=" & QSNAME & "&QSMAIL=" & QSMAIL & "&QSFOOT=" & QSFOOT & "&QSSUBJ=" & QSSUBJ
    Log(Params)'**** the log appears
    
    jobsm.Initialize("SendEmail","")
    jobsm.PostString(Main.BoWebSite & "/Asp/SendMail.asp", Params)
    Wait For (jobsm) JobDone(jobsm As HttpJob)
    If jobsm.Success Then
        result = "Success" & jobsm.GetString
    Else
        result = "unsuccess"
    End If
    
    Log(jobsm.GetString) '**** no log appears
    Return result
End Sub
 

ALBRECHT

Active Member
Licensed User
but that's not the goal
 

RJB

Active Member
Licensed User
Sorry, what is the goal? I thought you said: "but no way to log the result". I thought you wanted to log the result?
 

ALBRECHT

Active Member
Licensed User
because, as i said at the first post, I have a lot of sub routines that execute some poststrings actions with an ASP API.

So i have put the whole in a separate Code Module and now into a class (suggested by DonManFred) => and not into the main because of code organisation ...

So i have to get a return after the call :

B4X:
Dim SDM As SDMail
Dim resSDMail As ResumableSub
SDM.Initialize("ATITLE...", "THEMESSAGE ...", dbmap.get("AppUserName"), dbmap.get("AppUserMail"), "TheFooter", "Confirmation User Account")
resSDMail = SDM.SendAnEmail
 

ALBRECHT

Active Member
Licensed User
In fact it's like saying : how to recover the value of a resumableSub not from a Main Sub but from a Class ?

call : but no return value?
B4X:
Dim SDM As SDMail
Dim resSDMail As ResumableSub
SDM.Initialize("ATITLE...", "THEMESSAGE ...", dbmap.get("AppUserName"), dbmap.get("AppUserMail"), "TheFooter", "Confirmation User Account")
resSDMail = SDM.SendAnEmail
Class :
B4X:
Sub Class_Globals
    Private QSTT, QSMESS, QSNAME, QSMAIL, QSFOOT, QSSUBJ As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (aQSTT As String, aQSMESS As String, aQSNAME As String, aQSMAIL As String, aQSFOOT As String, aQSSUBJ As String)
    QSTT = aQSTT
    QSMESS = aQSMESS
    QSNAME = aQSNAME
    QSMAIL = aQSMAIL
    QSFOOT = aQSFOOT
    QSSUBJ = aQSSUBJ
End Sub

Public Sub SendAnEmail As ResumableSub
    Dim jobsm As HttpJob
    Dim Params As String
    'Dim result As String
    Params = "QSTT=" & QSTT & "&QSMESS=" & QSMESS & "&QSNAME=" & QSNAME & "&QSMAIL=" & QSMAIL & "&QSFOOT=" & QSFOOT & "&QSSUBJ=" & QSSUBJ
    Log(Params)
    
    jobsm.Initialize("SendEmail","")
    jobsm.PostString(Main.BoWebSite & "/Asp/SendMail.asp", Params)
    Wait For (jobsm) JobDone(jobsm As HttpJob)
    If jobsm.Success Then
        Return jobsm.GetString
    Else
        Return jobsm.GetString
    End If
End Sub
 

ALBRECHT

Active Member
Licensed User
In fact, i did not think i have to make 2 "wait for" on both sides

it works fine now with :

1/ Adding a first 'wait for' at the call into the Main :
B4X:
Dim SDM As SDMail
SDM.Initialize("eMailTitle","LongHtmlMessage", "ToName", "MailAdress", LongFooter, LongSubject)
Wait For (SDM.SendAnEmail) complete(resSDMail As String)
Log(resSDMail) 'Works Now
2/ Into the class : Put the return into a string and add Job.release at the and :
B4X:
Public Sub SendAnEmail As ResumableSub
    Dim jobsm As HttpJob
    Dim Params As String = "...." ' Post Charge
    Dim data As String

    jobsm.Initialize("SendEmail",Me)
    jobsm.PostString(Main.BoWebSite & "/Asp/SendMail.asp", Params)
    Wait For (jobsm) JobDone(jobsm As HttpJob)
    data = jobsm.GetString
    jobsm.release
    Return data
End Sub
Perfect, so i could have all my classes (with resumable sub ) sending and return values
 
Last edited:
Top