Is It Possible To Create A Downloader

jothis

Active Member
Licensed User
Is It Possible To Create A Progressbar While Downloading A File

Hi

I Created A program For Downloading A File But I cant See The Progress Of Downloading.
This Is My Code
B4X:
Sub Globals
      Dim Buffer(0) As byte

End Sub

Sub App_Start
     Form1.Show
     URL ="http://www.jrsoftware.org/download.php/is.exe"
      DownloadFile(AppPath & "\test.exe",URL)
End Sub
Sub DownloadFile (LocalFile,URL)
      Response.New1
      Request.New1(URL)
      Response.Value = Request.GetResponse 
     ' Msgbox("Download size: " & Response.ContentLength) 
     Reader.New1(Response.GetStream,True) 
      FileOpen(c1,LocalFile,cRandom)
      Writer.New1(c1,False)
      Dim buffer(4096) As byte
      count = Reader.ReadBytes(buffer(),4096)
      Do While count > 0
            Writer.WriteBytes2(buffer(),0,count)
            count = Reader.ReadBytes(buffer(),4096)
      Loop
      FileClose(c1)     
      Response.Close 
End Sub

So Can You Please Tell Me How To Do That
Jothis
:sign0085::sign0085:
 
Last edited:

specci48

Well-Known Member
Licensed User
Longtime User
Hi Jothis,

see the attached sample:

Create a progress bar (with ControlsEx.dll) and set the maximum value to the ContentLength. While downloading add the count value to the value of the progress bar after each write statement.


specci48
 

Attachments

  • Progress.sbp
    1.6 KB · Views: 196

jothis

Active Member
Licensed User
Thank you specci48 ,

But When I Try To Download A File Sized 10mb My Application Is Not Responding
jothis
:sign0085:
 

specci48

Well-Known Member
Licensed User
Longtime User
The file size should not be relevant. Maybe it's just a refreshing problem.

Try to put a "DoEvents" into the download routine:
B4X:
Do While count > 0
    DoEvents
    Writer.WriteBytes2(buffer(),0,count)
    progress.Value = progress.Value + count
    count = Reader.ReadBytes(buffer(),4096)
Loop


specci48
 

jothis

Active Member
Licensed User
Thank you For Helping me specci48
:sign0060:Now It Is Working Fine.:sign0060:
jothis
 
Top