Results 1 to 9 of 9

Thread: counting time

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    707

    Question

    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

  2. #2
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306

    Talking

    Try using a timer (not the control).

    If you want an API call, use the gettick.. whatever function.

  3. #3

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    707

    Unhappy timer

    thank

    How do I do it ?

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    ?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


    tumblingdown@hotmail.com

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  5. #5

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    707

    Question GetTickCount ?

    thanks


    How do I use the GetTickCount ?

    send me example please ?




  6. #6
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306

    Cool

    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

  7. #7
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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


    tumblingdown@hotmail.com

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  8. #8
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    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):
    Code:
        dtmStart = Now()
    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

  9. #9
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    956

    Re: counting time

    Thanks for the timer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width