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.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

st_steveConnect With a Mentor Commented:
ok...I'll send you the codes..but with the code fragment I've posted, you don't need the modules except one function: GenerateTempFile API I call to create a temporary file with a random (window-assigned) name.

Did any of you tried it and see if it worked?? I'm using it to automatically check for my application's updates on the's working..
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

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.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

hey, st steve,

I am using an Inet control, can I get your code that you wrote?
markj007Author Commented:
Yes, I am using the Inet control -- I would appreciate it if you could post the source code.

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
    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
    'refresh the form
    'saves the downloaded information into file
    Open tmpFile For Output As #1
        Print #1, txt
    '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
    If Err.Description <> "" Then
        sb.Panels(1) = "LiveUpdate Error (" & Err.Description & ")"
        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:

Thanks for your help!
markj007Author Commented:
Haven't tried it yet--but it looks like what I'm looking for.

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

From novice to tech pro — start learning today.