Results 1 to 28 of 28

Thread: [RESOLVED] Calculate speed and time remaining of download

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Calculate speed and time remaining of download

    Hi,

    I know that seconds elapsed/bytes transferred = bytes per second" transfer rate but I can not figure out how to get the seconds for the download using the Tick Count API?

    Thanks,


    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Calculate speed and time remaining of download

    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    That is VB.NET I am asking for VB6! I had already found that example. I don't see how to get the time elapsed?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Perhaps I don't understand the question but isn't it as simple as:
    Code:
    lngStart = GetTickCount()
    
    <do some work>
    
    lngEnd = GetTickCount()
    Elapsed= lngEnd - lngStart
    so if lngStart was 12345 and lngEnd was 23456 the elapsed time (Milliseconds) would be 11111

  5. #5

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    Perhaps I don't understand the question but isn't it as simple as:
    Code:
    lngStart = GetTickCount()
    
    <do some work>
    
    lngEnd = GetTickCount()
    Elapsed= lngEnd - lngStart
    so if lngStart was 12345 and lngEnd was 23456 the elapsed time (Milliseconds) would be 11111
    I will try that but I think this stop watch code is what I'm looking for.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Using the QueryPerformanceCounter and QueryPerformanceFrequency APIs will give you accurate timing but do you really need it to be highly accurate if you're measuring download speeds? I'd have thought that plus or minus 10mS would have been accurate enough.

  7. #7

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Using the Stop Watch code I found (link post #5) to download AntiVir Personal 13.0.0.3885 which, is 105.24MB but about 5 secs after I start the download the time elapsed in seconds is about.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    is about ...... what ?

    Perhaps you could post the code you're using - have you remembered to divide by the Frequency ?

  9. #9

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    is about ...... what ?

    Perhaps you could post the code you're using - have you remembered to divide by the Frequency ?
    Well, this line is in the original code

    vb Code:
    1. ElapsedSeconds = (currentTime - m_startTime - m_overhead) / m_freq

    Don't think that does what you are referring to since I am getting the wrong result.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Well, that looks OK what sort of numbers are you seeing?

  11. #11

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    Well, that looks OK what sort of numbers are you seeing?
    36390.00 and increases with each second of the download.

    Edit:

    Attachment removed!
    Last edited by Nightwalker83; Aug 28th, 2013 at 03:16 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  12. #12
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Well, I've just tried the Stopwatch code and it appears to work. I suspect there's a problem in where you're calling it- can you post the actual code you're using?

  13. #13

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    Well, I've just tried the Stopwatch code and it appears to work. I suspect there's a problem in where you're calling it- can you post the actual code you're using?
    I have just attached my code in post #11.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    You don't appear to start the Stopwatch anywhere I suspect you need
    Code:
            sw.start
            UserControl.AsyncRead URL, vbAsyncTypeByteArray, "file", vbAsyncReadForceUpdate

  15. #15

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    You don't appear to start the Stopwatch anywhere I suspect you need
    Code:
            sw.start
            UserControl.AsyncRead URL, vbAsyncTypeByteArray, "file", vbAsyncReadForceUpdate
    Ah ok! I probably deleted it by accident... I have added back into the project. Now the timer starts at 0 and counts up 1,2,3, etc. Although, that is time elapse not remaining?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  16. #16
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    TimeRemaining = (FileSize - Bytes_So_FarReceived) / CurrentSpeed

  17. #17
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    You've got a bit of a problem calculating the speed. I messed around with the code and introduced Label7 on Form1 for the Remaining Time and removed TimeElapsed Subroutine and modified
    Code:
    Private Sub UserControl_AsyncReadProgress(AsyncProp As AsyncProperty)
        
        On Error Resume Next
        picAsyncReadDownload.ScaleWidth = AsyncProp.BytesMax
        On Error GoTo 0
        lblProgress.Width = AsyncProp.BytesRead
        lblPercent.Caption = Int((AsyncProp.BytesRead / picAsyncReadDownload.ScaleWidth) * 100) & "%"
        Form1.Label5.Caption = Format(AsyncProp.BytesRead / (1024 * sw.ElapsedSeconds), "00.00")
        If CSng(Form1.Label5.Caption) <> 0 Then
            Form1.Label7.Caption = Format(((AsyncProp.BytesMax - AsyncProp.BytesRead) / 1024) / CSng(Form1.Label5.Caption), "00.00") & " Secs."
        End If
        Form1.Label5.Caption = Form1.Label5.Caption & " KB/Sec"
        Form1.Label6.Caption = Int((AsyncProp.BytesRead / picAsyncReadDownload.ScaleWidth) * 100) & "%"
    
    End Sub
    It needs a bit of a tidy up but appears to work.

    BTW: The save of the file fails as you're using the url including the http:// which, of course, the file system doesn't like

  18. #18

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    I have tried

    vb Code:
    1. Public Sub TimeElapsed()
    2. 'Form1.Label5.Caption = sw.ElapsedSeconds
    3. End Sub
    4.  
    5. Public Sub TransRate()
    6. Dim AsyncProp As AsyncProperty
    7.  rate = AsyncProp.BytesRead - sw.ElapsedSeconds
    8.   Form1.Label5.Caption = CStr(rate)
    9. End Sub
    10.  
    11. 'Public Sub TimeRemaining(AsyncProp As AsyncProperty)
    12. ' TimeRemaining = (AsyncProp.BytesMax - AsyncProp.BytesRead) / rate
    13. 'End Sub

    I have tried those but for some reason I can't get the value for rate to display in Label5. Nothing gets displayed in label5.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  19. #19
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Rate = bytesread / elapsed time
    You have to pass AsyncProp.BytesRead to your Sub from the AsyncProgress routine.

  20. #20

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    Rate = bytesread / elapsed time
    You have to pass AsyncProp.BytesRead to your Sub from the AsyncProgress routine.
    As far as I can see this this the only AsyncProp As AsyncProperty

    vb Code:
    1. UserControl.AsyncRead URL, vbAsyncTypeByteArray, "file", vbAsyncReadForceUpdate

    Do I just feed that in to TransRate, such as

    vb Code:
    1. TransRate(UserControl.AsyncRead URL, vbAsyncTypeByteArray, "file", vbAsyncReadForceUpdate)

    or do I need to modify it?

    Edit:

    BTW: The save of the file fails as you're using the url including the http:// which, of course, the file system doesn't like
    I thought the instr was suppose to deal with it?

    vb Code:
    1. Dim strParts() As String
    2.    
    3.     If InStr(1, LCase(URL), "http://") Then
    4.         strParts = Split(URL, "/")
    5.         strFilename = strParts(UBound(strParts))
    6.        
    7.         If Dir(App.Path & "\" & strFilename) <> vbNullString Then
    8.             If MsgBox("File exists, Overwrite?", vbYesNo) = vbNo Then
    9.                 Exit Sub
    10.             End If
    11.         End If

    That is from the original user control code.

    @Doogle,

    What is label7 holding? Label5 holds the value for speed.
    Last edited by Nightwalker83; Aug 26th, 2013 at 08:58 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  21. #21
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Label7 is the estimated time remaining

  22. #22

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    Label7 is the estimated time remaining
    Ah ok! That makes sense.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  23. #23
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    The 'Bad File' is coming from here:
    Code:
    Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
        
        Dim intFile  As Integer
        Dim bBytes() As Byte
        intFile = FreeFile()
        
      ' On Error GoTo errHandler
        
        Select Case AsyncProp.PropertyName
    
            Case "file"
                Open App.Path & "\" & URL For Binary As #intFile
    It's using the 'raw' URL

  24. #24

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    It's using the 'raw' URL
    Please explain?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  25. #25
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    When, for instance, I download Hijack This, this statement, in sub 'UserControl_AsyncReadComplete' fails
    Code:
    Open App.Path & "\" & URL For Binary As #intFile
    because URL contains: 'http://fs36.filehippo.com/7190/4e88bde118e14f16be4998b3142c85f0/HiJackThis.msi'

  26. #26

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by Doogle View Post
    When, for instance, I download Hijack This, this statement, in sub 'UserControl_AsyncReadComplete' fails
    Code:
    Open App.Path & "\" & URL For Binary As #intFile
    because URL contains: 'http://fs36.filehippo.com/7190/4e88bde118e14f16be4998b3142c85f0/HiJackThis.msi'
    How would I fix that, find another download url?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  27. #27
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate speed and time remaining of download

    Well, you've already set strFilename to a valid name so that's what you should be using
    Code:
                Open App.Path & "\" & strFilename For Binary As #intFile
    which works like a dream !!

  28. #28

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate speed and time remaining of download

    Quote Originally Posted by doogle View Post
    well, you've already set strfilename to a valid name so that's what you should be using
    Code:
                open app.path & "\" & strfilename for binary as #intfile
    which works like a dream !!
    doh!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width