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
Printable View
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
Maybe the next link can help http://www.vbforums.com/showthread.p...(progress-bar)
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?
Perhaps I don't understand the question but isn't it as simple as:
so if lngStart was 12345 and lngEnd was 23456 the elapsed time (Milliseconds) would be 11111Code:lngStart = GetTickCount()
<do some work>
lngEnd = GetTickCount()
Elapsed= lngEnd - lngStart
I will try that but I think this stop watch code is what I'm looking for.
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.
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. :confused:
is about ...... what ?
Perhaps you could post the code you're using - have you remembered to divide by the Frequency ?
Well, that looks OK what sort of numbers are you seeing?
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?
You don't appear to start the Stopwatch anywhere I suspect you need
Code:sw.start
UserControl.AsyncRead URL, vbAsyncTypeByteArray, "file", vbAsyncReadForceUpdate
TimeRemaining = (FileSize - Bytes_So_FarReceived) / CurrentSpeed
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
It needs a bit of a tidy up but appears to work.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
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 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.
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:
I thought the instr was suppose to deal with it?Quote:
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
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.
Label7 is the estimated time remaining
The 'Bad File' is coming from here:
It's using the 'raw' URLCode: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
When, for instance, I download Hijack This, this statement, in sub 'UserControl_AsyncReadComplete' fails
because URL contains: 'http://fs36.filehippo.com/7190/4e88bde118e14f16be4998b3142c85f0/HiJackThis.msi'Code:Open App.Path & "\" & URL For Binary As #intFile
Well, you've already set strFilename to a valid name so that's what you should be using
which works like a dream !!Code:Open App.Path & "\" & strFilename For Binary As #intFile