Time Taken To Download Web Page
This is how I am finding the time taken to download a web page:
Module Code:
Code:
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Public nNavigationTime As Long
Public Sub TimeElapsed()
nNavigationTime = GetTickCount
End Sub
Form Code:
Code:
Dim TimeTaken1 As String
Dim TimeTaken2 As String
Dim iDecimal As Integer
Private Sub wWeb_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
Call TimeElapsed
End Sub
Private Sub wWeb_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
Call GetDownloadTime
End Sub
Private Sub wWeb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Call GetDownloadTime
End Sub
Sub GetDownloadTime()
TimeTaken1 = (GetTickCount - nNavigationTime) / 1000
'formatting the download time
iDecimal = InStr(TimeTaken1, ".")
TimeTaken2 = Right(CStr(TimeTaken1), Len(CStr(TimeTaken1)) - iDecimal)
If (Len(TimeTaken2) = 0) Then
TimeTaken1 = TimeTaken1 & "000"
ElseIf (Len(TimeTaken2) = 1) Then
TimeTaken1 = TimeTaken1 & "00"
ElseIf (Len(TimeTaken2) = 2) Then
TimeTaken1 = TimeTaken1 & "0"
End If
sbrWeb.Panels(4).Text = TimeTaken1 & " sec."
End Sub
The above code doesn't evaluate the download time correctly on all occasions. Often it happens that though the status bar (sbrWeb) displays the time progression correctly, the time suddenly resets to 0 & starts from there again. I am not sure but I believe this happens on those pages which retrieve data from other servers.
Can someone please help me resolve this problem?