I am using the Microsoft Internet Control to create a web browser. I did like to find out how much time does it take for a web page to download. How do I accomplish this?
The downloading time calculated should be as precise as possible.
Printable View
I am using the Microsoft Internet Control to create a web browser. I did like to find out how much time does it take for a web page to download. How do I accomplish this?
The downloading time calculated should be as precise as possible.
Use the DateDiff() function....
At the start of your function get Now..
That should do it.VB Code:
Dim This This = Now 'Load page here.... TimeElapsed = DateDiff("s", Now & This) 'Gives you the difference in Seconds.
Also, you should put a Do Until loop around loading the page, so it won't calculate the time until it's done.
Have a module level variable (lets call it nNavigationTime in this example) that you assign the return value of GetTickCount before you navigate to a new URL. You can then get the time it took by adding this code in the DocumentComplete event.VB Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) If (pDisp Is WebBrowser1.Object) Then nNavigationTime = GetTickCount - nNavigationTime MsgBox "It took " & nNavigationTime / 1000 & " seconds to download this page" End If End Sub
Well, that works too... =\Quote:
Originally Posted by Joacim Andersson
But what is this GetTickCount?
Oh sorry. It's an API function.Quote:
Originally Posted by arpan_de
VB Code:
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
But under which sub in the Module should nNavigationTime be assigned the return value of GetTickCount? Is this correct?VB Code:
'[u]Form Code[/u] 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 '[u]Module Code[/u] Private Declare Function GetTickCount Lib "kernel32.dll" () As Long Public nNavigationTime As Long Public Sub TimeElapsed() nNavigationTime = GetTickCount End Sub
OK......OK......I got it Joacim!