vanishing string/scope of global string

Avon

Member
Licensed User
Longtime User
I declare a string spage, a HHTPClient and a HTTPRequest in the Globals sub. In an OnClick sub I get a global request object and make a HTTP request. On success I assign the results of the request to the string spage and show a fragment of it in a msgbox. Then I call a sub which tests the length of spage and behold! it is zero.

What am I doing wrong, please?

B4X:
Sub Button1_Click

   ProgressDialogShow("Loading data from www")
   URL = "http://www.bbc.co.uk"
   request.InitializeGet(URL)
   request.Timeout = 10000 'set timeout to 10 seconds
   If HttpClient1.Execute(request, 300) = False Then Msgbox("error","err")
   
 End Sub
 Sub Http_ResponseSuccess (Response As HttpResponse, TaskId As Int)
 
     ProgressDialogHide
     spage = (Response.GetString("UTF8"))
     Msgbox(spage.SubString2(1, 100),"results") '<----- results shown
     scrape
 End Sub
Sub scrape
    dim l as int
    l = spage.length()
    If l = 0 Then
     Msgbox("no data from HTTP GET","error") '<----- error shown
         Return
     End If
End Sub
 

kickaha

Well-Known Member
Licensed User
Longtime User
check the spelling of spage in your dim statement, as it is behaving as if spage is a local variable.
 
Upvote 0

Avon

Member
Licensed User
Longtime User
Thanks for your replies chaps.

I found it. I'm doing something in the code executed after though in the same sub as the length test and msgbox which appears to have murdered the string for the entire sub.

Next step - find out which statement is to blame.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…