Newbie Question: httputils2 related

sktanmoy

Active Member
Licensed User
Longtime User
Example code:
B4X:
Sub JobDone(Job As HttpJob)
   If Job.Success = True Then
      Return Job.GetString
   Else
      ToastMessageShow("Server Connection Was Failed", False)
   End If
End Sub

How can I get the received value (bitmap or string) within other sub?:sign0104:
 

Reinosoft

Member
Licensed User
Longtime User
Sub

You can use Return to set a value to a sub

Sub Test(ValueIn as integer) as Boolean
If Valuein>0 Then
Return True​
Else
Return False​
End If​
End Sub

If you run the sub eg like this Msgbox(Test(1))
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Can you explain a little further ?

Hi sktanmoy,

Can you please explain what do you want to do ?

I've played a little with httputils2. I'm a newbie too, but I will try to help you.

José
 
Upvote 0

sktanmoy

Active Member
Licensed User
Longtime User
Hi sktanmoy,

Can you please explain what do you want to do ?

I've played a little with httputils2. I'm a newbie too, but I will try to help you.

José

José, actually I've downloaded a image using httputills2. So now want to use the bitmap image from other sub.

I've tried with
B4X:
Sub JobDone (Job as httpjob)
if job.success = true then
return true
end if
End Sub

and from other sub, job1.getbitmap. But No luck. So need to know how to use value from other sub.
 
Upvote 0

sktanmoy

Active Member
Licensed User
Longtime User
I'm sorry but I do not understand the question. You can use a global variable and assign it the bitmap.

In activity create, httputills2 will download the image. I'll use that later from another sub.

I've tried this one

B4X:
Sub Globals
   Dim b As Bitmap
End Sub

B4X:
Sub JobDone (Job As HttpJob) 

    If Job.Success = True Then
      ProgressDialogHide
      b = Job.GetBitmap
    End If
    Job.Release
   
End Sub

But I could not use b from other sub. b returns nothing.
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Are you sure the bitmap is being downloaded ?

Is it something like this you want to do ?

B4X:
Sub Globals

  Dim b As Bitmap
  Dim p As Panel
  Dim iv As ImageView

End Sub

Sub Activity_Create(FirstTime As Boolean)

  p.Initialize("") ' initializes a panel
  iv.Initialize("") ' initializes an imageview
  Activity.AddView(p, 0, 0, 100, 100) ' add the panel to activity (100x100)
    
   Dim job As HttpJob
   
   job.Initialize("dl_test", Me)
   job.Download("http://www.where your image is on the web")

  add_image ' a sub that will show the image
   
End Sub

Sub add_image

   p.AddView(iv,0,0,100,100) ' add the imageview to a panel...in a different sub

End Sub

Sub JobDone (Job As HttpJob)
   
  If Job.Success = True Then
   b=Job.GetBitmap
   iv.Bitmap=b ' adds the bitmap to an imageview
   
  Else
       
        ToastMessageShow("Error: " & Job.ErrorMessage, True)

  End If

End Sub

José

PS - You don't actually need b in this so simple situation as it could be assigned directly to iv, but I left like that, so that you can play around.
 
Last edited:
Upvote 0
Top