Android Question Returning Value from Resumable Sub

Discussion in 'Android Questions' started by DawningTruth, Jun 23, 2019.

  1. DawningTruth

    DawningTruth Active Member Licensed User

    I have a sub that uses a resumable sub to fetch website data. As you cannot return a value from a resumable sub, how do I get the value of the website data out of the sub.

    Here is my code:

    Code:
    Private Sub mySub
      
        FetchWebsite(
    "https://duckduckgo.com"Array As String("q","test","t","hj","ia","web"))
        
    Wait For FetchWebsite_Complete

        
    'Somehow use myJob.GetString value

    End Sub


    Sub FetchWebsite(url As String, param() As String)
     
        
    Dim myJob As HttpJob
     
        myJob.Initialize(
    "", Me)
        myJob.Download2(url,param)
        
    Wait For (myJob) JobDone (myJob As HttpJob)
        
    If myJob.Success Then
            
    Log(myJob.GetString)
        
    Else
            
    Log("Error: " & myJob.ErrorMessage)
        
    End If
        myJob.Release
     
        CallSubDelayed(Me, 
    "FetchWebsite_Complete")
     
        
    'Somehow return myJob.GetString

    End Sub
    Any assistance is appreciated :)
     
    Last edited: Jun 23, 2019
  2. asales

    asales Well-Known Member Licensed User

    mangojack and José J. Aguilar like this.
  3. Brandsum

    Brandsum Well-Known Member Licensed User

    Code:
    Private Sub mySub
     
        
    Wait For (FetchWebsite("https://duckduckgo.com"Array As String("q","test","t","hj","ia","web"))) complete(data As String)
        
    Log(data)

    End Sub


    Sub FetchWebsite(url As String, param() As StringAs ResumableSub
     
        
    Dim myJob As HttpJob
         
    Dim data As String
        myJob.Initialize(
    "", Me)
        myJob.Download2(url,param)
        
    Wait For (myJob) JobDone (myJob As HttpJob)
        
    If myJob.Success Then
            data = myJob.GetString
        
    Else
            data = myJob.ErrorMessage
        
    End If
        myJob.Release
        
    Return data
    End Sub
     
  4. DawningTruth

    DawningTruth Active Member Licensed User

  5. DawningTruth

    DawningTruth Active Member Licensed User

    Thx, so much Brandsum.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice