Link to home
Start Free TrialLog in
Avatar of markj007
markj007

asked on

Tracking Download Progress..

Is there a way to track how much of a file has been downloaded (in Kilobytes) when using one of the internet controls with VB?

I'm trying using a progress bar to show download completion, but I don't know how to check for that.

Sample code would be appreciated.

Thanks!
Mark
Avatar of st_steve
st_steve

what control are you using? are you using Inet control? if so I have written some code to track the download progress....let me know....will post the code if you want it (and if you're using inet control)
Instead of the Internet controls you could possible use a small dll (with full source code) you can find at

  http://vbaccelerator.com/codelib/submit/asynctx.htm

This dll give you the ability to download multiple files at the same time in the background, and it will also raise a event now and then to show how much (%) of the files has been downloaded.
hey, st steve,

I am using an Inet control, can I get your code that you wrote?
Avatar of markj007

ASKER

Yes, I am using the Inet control -- I would appreciate it if you could post the source code.

Thanks.
ok...sure....give me a few mins to dig out the code, ok?

'requires INetConnection.bas, Registry.bas, Useful.bas, WinAPI.bas
'Inet and Windows Common Controls

Dim tmpFile As String

Private Sub Form_Load()
    tmpFile = GenerateTempFile(App.Path)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    If dir(tmpFile) <> "" And tmpFile <> "" Then Kill tmpFile
End Sub

'put this in a command button or something
    On Error GoTo ErrorHandler
    Dim txt As String, UpdateAvailable As Boolean
    Dim b() As Byte, StartTime As Long
   
    StartTime = Timer
    b() = Inet1.OpenURL("file you want to download!", 1)
    'wait for 60 seconds or until connected
    While Inet1.StillExecuting And (Timer - StartTime) < 60
        DoEvents        'pass control to OS
      'update the progress bar
      pb.Value=UBound(b)-1
      pb.Refresh
    Wend
   
    txt = ""
   
    'set up progress bar
    pb.Value = 0
    If (UBound(b) - 1) > 0 Then
        pb.Max = UBound(b) - 1
        Label1.Visible = True
        pb.Visible = True
    End If
   
    'load the downloaded information into a variable
    For t = 0 To UBound(b) - 1
        txt = txt + Chr(b(t))
        'update progress bar
        pb.Value = t
    Next
    'refresh the form
    Me.Refresh
   
    'saves the downloaded information into file
    Open tmpFile For Output As #1
        Print #1, txt
    Close
   
    'file length will be 2 bytes if download failed!
    If FileLen(tmpFile) < 90 Then
        sb.Panels(1) = "Download of configuration file failed."
        cmdRetry.Enabled = True
        Exit Sub
    End If
   
   
    Exit Sub
ErrorHandler:
    If Err.Description <> "" Then
        sb.Panels(1) = "LiveUpdate Error (" & Err.Description & ")"
    Else
        sb.Panels(1) = "An Error occurred while LiveUpdate was in progress."
    End If
    cmdRetry.Enabled = True
End Sub


IF you want the three modules mentioned at the top of the code, msg me back....I use a temporary file creation automatically.
I hate to keep bugging you, but can we get the .bas files?
here is my email if it would be easier for you:

jtzoumis@bushnell.com

Thanks for your help!
ASKER CERTIFIED SOLUTION
Avatar of st_steve
st_steve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Haven't tried it yet--but it looks like what I'm looking for.

Thanks.
ok....hope it was what you're looking for...coz you already gave me the points..thanks..