Linking ProgressBar to file download?

Discussion in 'Questions (Windows Mobile)' started by N1c0_ds, Oct 29, 2008.

  1. N1c0_ds

    N1c0_ds Active Member Licensed User

    I'm using the ProgressBar control to show the download progress for various CAB files downloaded from various servers. I will need a progress bar to show that the program is not dead but I don't know how to link it. Here's the DownloadFile sub:

    Code:
    Sub DownloadFile (LocalFile,URL)
          Response.New1
          Request.New1(URL)
          Response.Value = Request.GetResponse 
    'Launch the request and get the response.
         Response.Value = Request.GetResponse 'Launch the request and get the response.
          Reader.New1(Response.GetStream,true'Use a BinaryFile object to read the data from the Response stream.
          FileOpen(c1,LocalFile,cRandom)
          Writer.New1(c1,
    false)
          
    Dim buffer(4096As 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 
    'Close the Response stream.
    End Sub 'Get files
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can do something like:
    Code:
    Sub DownloadFile (LocalFile,URL)
          Response.New1
          Request.New1(URL)
          Response.Value = Request.GetResponse 
    'Launch the request and get the response.
         Response.Value = Request.GetResponse 'Launch the request and get the response.
          Reader.New1(Response.GetStream,true'Use a BinaryFile object to read the data from the Response stream.
          FileOpen(c1,LocalFile,cRandom)
          Writer.New1(c1,
    false)
          
    Dim buffer(4096As byte
          bar.Maximum = Reader.Length
          bar.value = 
    0
          bar.refresh
          count = Reader.ReadBytes(buffer(),
    4096)
          
    Do While count > 0
                Writer.WriteBytes2(buffer(),
    0,count)
                count = Reader.ReadBytes(buffer(),
    4096)
                bar.value = bar.value + count
                bar.refresh
          
    Loop
          FileClose(c1)     
          Response.Close 
    'Close the Response stream.
    End Sub 'Get files
     
  3. N1c0_ds

    N1c0_ds Active Member Licensed User

    It produces an error here. I tested "bar.Response=Response.ContentLength" and it works perfectly.
     
    Last edited: Nov 2, 2008
  4. Erel

    Erel Administrator Staff Member Licensed User

    I guess you mean bar.Maximum=Response.ContentLength.
     
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