|
-
Nov 8th, 2000, 05:46 AM
#1
Thread Starter
Fanatic Member
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
-
Nov 8th, 2000, 08:41 AM
#2
Hyperactive Member
Try using a timer (not the control).
If you want an API call, use the gettick.. whatever function.
-
Nov 8th, 2000, 08:47 AM
#3
Thread Starter
Fanatic Member
timer
-
Nov 8th, 2000, 08:54 AM
#4
Hyperactive Member
?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.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 8th, 2000, 09:39 AM
#5
Thread Starter
Fanatic Member
GetTickCount ?
thanks
How do I use the GetTickCount ?
send me example please ?
-
Nov 8th, 2000, 09:53 AM
#6
Hyperactive Member
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
-
Nov 8th, 2000, 10:23 AM
#7
Hyperactive Member
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.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 8th, 2000, 01:51 PM
#8
Hyperactive Member
I prefer the following method:
At the beginning of the Sub or Function you want to do the counting add:
Code:
Dim dtmStart As Date
Add this to where you want to start counting (before the loop):
Assuming you have a text box you want to display the time elapsed, when your loops is done add this line:
Code:
Me.text1 = Elapsed(DateDiff("s", dtmStart, Now()))
You'll need to add this function to either the form or a global module:
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
-
Jan 7th, 2007, 11:49 AM
#9
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|