Calculating time difference in milliseconds in VB6
Posted by scmay on March 23, 2007
As a VB6 programmer, I am finding even more difficult to find pieces of VB6 code these days. As all VB6 programmers might know, VB6 and VB.NET has slight differences (VB.NET is claimed to be 100% Object Oriented)
So here is a snippet of code that calculates the time difference in milliseconds
Public Declare Function GetTickCount Lib “kernel32” () As Long ‘For timer
Function_name()
Dim dtStart As Long
Dim dtEnd As Long
Dim result As Long
Dim i As IntegerdtStart = GetTickCount
‘Do task
dtEnd = GetTickCount
result = dtEnd – dtStart
MsgBox “Duration is ” & result & ” milliseconds.”
End Function
Taken from here
Tom said
Thanks, that helped.
Sean Henderson said
Thanks for this piece. Works great. You may want to look at a plugin called codesnippet (http://wordpress.org/extend/plugins/codesnippet-20/) so that its easier to copy and paste code from your blog. I noticed it didn’t paste nicely into vb6. Thanks again.
Prabhakaran said
Great, It helped me a lot.
Thanks
Svend said
Great!
Thanks – a great help 🙂
Svend
Denmark
Faster Windows 7 said
Hi, Thanks. Having been going through exactly the same issue. Solved now Regards.
hacking tribe said
Thanks! 😉
Mayank Jaiswal said
While copying the code, following characters are not copied properly
”
‘
So beware.
Else code works perfectly. Thanks
patricio paredes said
Public Declare Function GetTickCount Lib “kernel32? () As Long ‘For timer
Public Function fn_iDaMilisegundos() As Integer
fn_iDaMilisegundos = GetTickCount() Mod 1000
End Function
Ejecuto:
Dim sHora As String
sHora = Format(Now, “yyyy-mm-dd Hh:Nn:Ss”) & “.” & Format(fn_iDaMilisegundos(), “000”)
me da
2011-10-18 16:13:08.953
y no inicializo nada!, unicamante la llamo.