Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to track download rate and byte?

Status
Not open for further replies.

Jason231

MIS
Apr 15, 2006
43
NL
could any one show me how i can track file downoad rate such as .rar file or .exe file using prograss bar and byte rate. Thanks
 
Are you trying to use the link to his code posted by Hypetia in thread222-1220238?

If so could you show us what you have got and any errors you encounter that are stopping the code from downloading the file?

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Harly thank u for u reply. i only changed the code of hypetia so that it downloads my file in a remote server. It only worked once but the .rar file was corupted!The rest of the time did not work!The window and prograss bar does not change!. i keep checking the location of c:\ for the file but i can not see it.I tried re open the project again but no luck

Code:
Option Explicit
Private Sub Form_Load()
    'initialize and stage controls
    ScaleMode = vbPixels
    Text1.Move 5, 115, 300, 20
    Text2.Move 5, 135, 300, 20
    ProgressBar1.Move 5, 155, 300, 20
    Command1.Move 4, 175, 83, 23
    Label1.Move 100, 180, 200, 20
    
    'Text1.Locked = True
    'Text2.Locked = True
    
  [b]  Text1.Text = "[URL unfurl="true"]http://www.site.com/~test/testing/Color.rar"[/URL][/b]
  [b]  Text2.Text = "C:\Color.rar"[/b]
    ProgressBar1.Max = 100
    Command1.Caption = "Download"
    Label1.Caption = "<- Click to start downlaod"
End Sub


Private Sub Command1_Click()
    Inet1.Protocol = icHTTP
    Command1.Enabled = False
    'start download
    Inet1.Execute Trim$(Text1.Text), "GET"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Dim Buffer() As Byte 'buffer for receiving data from inet control.
    On Error Resume Next
    Select Case State
        Case icResponseCompleted
            Open Text2.Text For Binary As #1 'open output file
                Do
                    DoEvents
                    Buffer = Inet1.GetChunk(512, icByteArray) 'get the data chunk
                    If UBound(Buffer) = -1 Then Exit Do 'no more data
                    Put #1, , Buffer    'write data to file
                    ProgressBar1.Value = Seek(1) - 1 'ammount of data downloaded
                    Label1.Caption = "Downloaded " & ProgressBar1.Value & " bytes, " & _
                    FormatPercent(ProgressBar1.Value / ProgressBar1.Max)
                Loop
            Close
            Picture = LoadPicture(Text2.Text) 'display the downloaded image
        Case icResponseReceived
            If LenB(Inet1.GetHeader("Content-Length")) > 0 Then
                ProgressBar1.Max = CLng(Inet1.GetHeader("Content-Length")) 'total size
            End If
    End Select
End Sub
 
To be honest, I'm stumped then.

I've used Hypetia's code to download gif's, zip's, pdf's, exe's and rar files and never encountered a problem with any of them.

Sorry I couldn't be more help.

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
For a test, have you tried downloading a different .rar file using the code?

The one I tested with was at
Just to see if you can get it to work with that one?

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
gives me error 404 (Page Not Found)

Erm, I know this sounds like a silly question, but have you double-checked that this is correct URL?

I've just tested the code on a variety of URL's and it works fine here.

TIP: Comment out On Error Resume Next and see what happens then.
 
yes i tried it with the like u posted and did not download this time too:-( That is why i look for diffrent ways! It seems it is not reliable method.
 
What did it do when you tried using the link I posted?

Did it error (if so what error did it throw)?, did it crash?, did it just hang (if so how long before you stopped the application)?

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Also, I see you've had problems with this for some time. Grab a copy of Ethereal from - you'll also need WinPcap as well. If you're doing any sort of network programming, it's invaluable.

This will let you see exactly what is happening and the bytes being sent and received. This may help you track the source of the problem - the code itself seems to be fine.
 
It looks like the pic once i click nothing happens no error for a long time untill i stop or close it !!

fa0f351d.jpg


comaboy thank u for introducing me to this too. could u give on some guides on how to use it . thanks
 
How long is "a long time"?

It gets to the stage you're at as soon as you click the command button. It takes a little while to start the visible portion of the download when I run the code.

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Indeed, there is a pause before the download starts, this is because the program
* Makes the initial http request
* waits for the server's response
* Parses response to get the content-size header and set the ProgressBar
* begins the actual download.
Then everthing seems to work perfectly here. What is your connection speed?

Ethereal: Well, basically, you choose which network interface you want to monitor and it'll show you the packets being sent and received. You can then right-click a particular packet and view it's entire converstaion. There is a lot of documentation on ethereal.com.
 
comaboy,

Yes, that was what I was eluding to in my post. Just explaining to the OP that a pause is expected [smile]

I was trying to (as I think you are as well) find out what the OP is considering a "long time"

Cheers

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
hmmm... Jason, this may be a silly question, but is your Personal Firewall properly configured to allow VB6 network access? You seem to have had no luck with any method suggested to date.
 
well the strange part is that it worked 2 times and after that never worked!! coaboy i usually download things with no probem i have some 3th party applications that they do exactly like this with out any problem so firewall is not the problem!
 
Certain firewalls can block indivual applications. That was the reason for the question.

Just tried it twice in quick succession, the second attempt threw up an error "Unable to complete request". The is usually caused on the Server side. Give me a moment to add some error checking to your code...
 
Ok, replace your code with that listed below. I've added some quick and dirty error checking. Let's see if we can't find the source of the problem.

Code:
Option Explicit
Private Sub Form_Load()
    'initialize and stage controls
    ScaleMode = vbPixels
    Text1.Move 5, 115, 300, 20
    Text2.Move 5, 135, 300, 20
    ProgressBar1.Move 5, 155, 300, 20
    Command1.Move 4, 175, 83, 23
    Label1.Move 100, 180, 200, 20
    
    'Text1.Locked = True
    'Text2.Locked = True
    
    Text1.Text = "[URL unfurl="true"]http://www.rarlab.com/rar/RARaddin_48x48.theme.rar"[/URL]
    Text2.Text = "C:\RARaddin_48x48.theme.rar"
    ProgressBar1.Max = 100
    Command1.Caption = "Download"
    Label1.Caption = "<- Click to start downlaod"
End Sub


Private Sub Command1_Click()
    Inet1.Protocol = icHTTP
    Command1.Enabled = False
    'start download
    Inet1.Execute Trim$(Text1.Text), "GET"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Dim Buffer() As Byte 'buffer for receiving data from inet control.
    On Error GoTo err_Inet1_StateChanged
    Select Case State
        Case icResponseCompleted
            Open Text2.Text For Binary As #1 'open output file
                Do
                    DoEvents
                    Buffer = Inet1.GetChunk(512, icByteArray) 'get the data chunk
                    If UBound(Buffer) = -1 Then Exit Do 'no more data
                    Put #1, , Buffer    'write data to file
                    ProgressBar1.Value = Seek(1) - 1 'ammount of data downloaded
                    Label1.Caption = "Downloaded " & ProgressBar1.Value & " bytes, " & _
                    FormatPercent(ProgressBar1.Value / ProgressBar1.Max)
                Loop
            Close
        Case icResponseReceived
            If LenB(Inet1.GetHeader("Content-Length")) > 0 Then
                ProgressBar1.Max = CLng(Inet1.GetHeader("Content-Length")) 'total size
            End If
    End Select
exit_Inet1_StateChanged:
    Exit Sub
err_Inet1_StateChanged:
    Dim nextAction As Long
    nextAction = MsgBox("Oh dear, an error occured. It was reported as '" & Err.Description & "'. What would you like to do?", 18)
    If nextAction = 3 Then
        Inet1.Cancel
        Resume exit_Inet1_StateChanged
    Else
        Resume Next
    End If
End Sub
 
Thanks cobaboy for helping . Here is what i get when i click on the button :


problem4.jpg



it cicked on retry and one more time i got the same massage and after that nothing happend!!
 
Change the error checking section to this:
Code:
err_Inet1_StateChanged:
    Dim nextAction As Long
    Debug.Print StrConv(Buffer, vbUnicode)
    nextAction = MsgBox("Oh dear, an error occured. It was reported as '" & Err.Description & "'. What would you like to do?", 18)
    If nextAction = 3 Then
        Inet1.Cancel
        Resume exit_Inet1_StateChanged
    Else
        Resume Next
    End If
End Sub
When it errors out, you'll see what's actually been sent from rarlabs.com to you (in the Immediate window). This should help figure out what's going wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top