Hi
I have a procedure and a my friend say that if I put a command It will be more fast.
I want couting time with and without command in the procedure, How do I do to counting the passed in te VB ?
thank you in advance
Printable View
Hi
I have a procedure and a my friend say that if I put a command It will be more fast.
I want couting time with and without command in the procedure, How do I do to counting the passed in te VB ?
thank you in advance
Try using a timer (not the control).
If you want an API call, use the gettick.. whatever function.
thank
How do I do it ?
?In what way are you conting time?
If you want the difference between to time stamps, use something like datediff?
Also, there is and api call GetTickCount. This returns the number of milliseconds since the computer was turned on.
So at one point, you can record the tick count, then later record the tick count again, take the latter form the former, and you have the number of milliseconds in between. This is very fast.
td.
thanks
How do I use the GetTickCount ?
send me example please ?
Dim Sng_Timer As Single
Sng_Timer = Timer
....
....
....
....
Msgbox Timer - Sng_Timer
By the way, if you want to convert a time in seconds to a string, try this:
Function f_TimerEnglish(dbl_Seconds As Double) As String
Dim int_Seconds As Integer
Dim int_Minutes As Integer
Dim int_Hours As Integer
Dim int_Days As Integer
Dim dbl_Res As Double
Dim str_String As String
int_Seconds = Int(dbl_Seconds)
dbl_Res = f_Redondea(dbl_Seconds - Int(dbl_Seconds), 3)
int_Minutes = Int(int_Seconds / 60)
int_Hours = Int(int_Minutes / 60)
int_Days = Int(int_Hours / 24)
Do While int_Seconds >= 60
int_Seconds = int_Seconds - 60
Loop
Do While int_Minutes >= 60
int_Minutes = int_Minutes - 60
Loop
Do While int_Hours >= 24
int_Hours = int_Hours - 24
Loop
f_TimerEnglish = ""
If int_Days > 0 Then
If int_Days = 1 Then
str_String = " day"
Else
str_String = " days"
End If
f_TimerEnglish = f_TimerEnglish & int_Days & str_String
End If
If int_Hours > 0 Then
If int_Hours = 1 Then
str_String = " hour"
Else
str_String = " hours"
End If
If Len(Trim(f_TimerEnglish)) > 0 Then
f_TimerEnglish = f_TimerEnglish & ", "
End If
f_TimerEnglish = f_TimerEnglish & int_Hours & str_String
End If
If int_Minutes > 0 Then
If int_Minutes = 1 Then
str_String = " minute"
Else
str_String = " minutes"
End If
If Len(Trim(f_TimerEnglish)) > 0 Then
f_TimerEnglish = f_TimerEnglish & ", "
End If
f_TimerEnglish = f_TimerEnglish & int_Minutes & str_String
End If
If int_Seconds > 0 Then
If int_Seconds + dbl_Res = 1 Then
str_String = " second"
Else
str_String = " seconds"
End If
If Len(Trim(f_TimerEnglish)) > 0 Then
f_TimerEnglish = f_TimerEnglish & ", "
End If
f_TimerEnglish = f_TimerEnglish & int_Seconds + dbl_Res & str_String
End If
End Function
Public Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
dim lRtrn as long
lRtrn = GetTickCount
'/ lRtrn is the number of milliseconds since boot up.
td.
I prefer the following method:
At the beginning of the Sub or Function you want to do the counting add:
Add this to where you want to start counting (before the loop):Code:Dim dtmStart As Date
Assuming you have a text box you want to display the time elapsed, when your loops is done add this line:Code:dtmStart = Now()
You'll need to add this function to either the form or a global module:Code:Me.text1 = Elapsed(DateDiff("s", dtmStart, Now()))
Code:Public Function Elapsed(plngSeconds As Long) As String
Dim strReturn As String
If plngSeconds > 5999 Then
strReturn = plngSeconds \ 3600
plngSeconds = plngSeconds Mod 3600
strReturn = strReturn & ":" & Format(plngSeconds \ 60, "00") & ":" & Format(plngSeconds Mod 60, "00")
ElseIf plngSeconds > 59 Then
strReturn = plngSeconds \ 60 & ":" & Format(plngSeconds Mod 60, "00")
Else
strReturn = "0:" & Format(plngSeconds, "00")
End If
Elapsed = strReturn
End Function
Thanks for the timer