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
markj007Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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 web..it's working..
0
 
st_steveCommented:
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)
0
 
VbmasterCommented:
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.
0
Never miss a deadline with monday.com

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

 
JoeyT042499Commented:
hey, st steve,

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

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

'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.
0
 
JoeyT042499Commented:
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!
0
 
markj007Author Commented:
Haven't tried it yet--but it looks like what I'm looking for.

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

From novice to tech pro — start learning today.