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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
JoeyT042499Commented:
hey, st steve,

I am using an Inet control, can I get your code that you wrote?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
st_steveCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.