|
-
Aug 25th, 2013, 10:54 PM
#1
[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
-
Aug 26th, 2013, 12:22 AM
#2
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 ...
-
Aug 26th, 2013, 01:08 AM
#3
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
-
Aug 26th, 2013, 01:41 AM
#4
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
-
Aug 26th, 2013, 02:06 AM
#5
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 26th, 2013, 02:16 AM
#6
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.
-
Aug 26th, 2013, 03:04 AM
#7
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
-
Aug 26th, 2013, 03:08 AM
#8
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 ?
-
Aug 26th, 2013, 03:17 AM
#9
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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:
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
-
Aug 26th, 2013, 03:59 AM
#10
Re: Calculate speed and time remaining of download
Well, that looks OK what sort of numbers are you seeing?
-
Aug 26th, 2013, 04:03 AM
#11
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 26th, 2013, 04:10 AM
#12
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?
-
Aug 26th, 2013, 04:13 AM
#13
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 26th, 2013, 04:24 AM
#14
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
-
Aug 26th, 2013, 04:34 AM
#15
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 26th, 2013, 04:39 AM
#16
Re: Calculate speed and time remaining of download
TimeRemaining = (FileSize - Bytes_So_FarReceived) / CurrentSpeed
-
Aug 26th, 2013, 05:34 AM
#17
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
-
Aug 26th, 2013, 05:50 AM
#18
Re: Calculate speed and time remaining of download
I have tried
vb Code:
Public Sub TimeElapsed() 'Form1.Label5.Caption = sw.ElapsedSeconds End Sub Public Sub TransRate() Dim AsyncProp As AsyncProperty rate = AsyncProp.BytesRead - sw.ElapsedSeconds Form1.Label5.Caption = CStr(rate) End Sub 'Public Sub TimeRemaining(AsyncProp As AsyncProperty) ' TimeRemaining = (AsyncProp.BytesMax - AsyncProp.BytesRead) / rate '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
-
Aug 26th, 2013, 06:36 AM
#19
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.
-
Aug 26th, 2013, 07:31 PM
#20
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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:
UserControl.AsyncRead URL, vbAsyncTypeByteArray, "file", vbAsyncReadForceUpdate
Do I just feed that in to TransRate, such as
vb Code:
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:
Dim strParts() As String If InStr(1, LCase(URL), "http://") Then strParts = Split(URL, "/") strFilename = strParts(UBound(strParts)) If Dir(App.Path & "\" & strFilename) <> vbNullString Then If MsgBox("File exists, Overwrite?", vbYesNo) = vbNo Then Exit Sub End If 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
-
Aug 26th, 2013, 11:58 PM
#21
Re: Calculate speed and time remaining of download
Label7 is the estimated time remaining
-
Aug 27th, 2013, 12:11 AM
#22
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 27th, 2013, 12:18 AM
#23
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
-
Aug 27th, 2013, 12:33 AM
#24
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 27th, 2013, 12:41 AM
#25
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'
-
Aug 27th, 2013, 12:43 AM
#26
Re: Calculate speed and time remaining of download
 Originally Posted by Doogle
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
-
Aug 27th, 2013, 12:50 AM
#27
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 !!
-
Aug 27th, 2013, 12:54 AM
#28
Re: Calculate speed and time remaining of download
 Originally Posted by doogle
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|