Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dufference in milliseconds (6.0)

    i have this part of code:

    ...
    Dim B As Date, A As Date, DIFF As Date
    ...


    Do Until objFile.AtEndOfStream

    B = Format((Now), "S")
    ReDim Preserve ARRAY_LINEA(I)
    ARRAY_LINEA(I) = objFile.ReadLine
    I = I + 1
    Loop
    A = Now

    DIFF = DateDiff("S", B, A)

    i want calculate diff from init time and end of time to calculate millisecods for loop...
    in all case have "0"(!!!!!????)

    In efect i have calculate with my watch about 2 seconds

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Dufference in milliseconds (6.0)

    <P ID="edit" class=small>(Edited by jscher2000 on 10-May-08 14:11. Hmmm...)</P>The return value of the DateDiff function is a Long integer, not a Date. More on this function: DateDiff Function (Visual Basic) @ MSDN.

    Added: Actually, that page is for VB.Net. Here's a page for VBA, which is more similar to VB6: DateDiff Function @ MSDN. According to that page, it returns a variant of type Long.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Difference in milliseconds (6.0)

    You should consider using the Timer function. It's available in VBA, so I assume it is available in VB6. If you add this macro to a Word document, you can see how it works.

    <code>Sub ShowTimer()
    Dim sTime As Single, intCount As Integer
    sTime = Timer
    With ActiveDocument
    ' Kill some time
    For intCount = 1 To .Styles.Count
    Debug.Print .Styles(intCount).NameLocal
    Next
    ' Show time interval
    With .Content
    .Delete
    .InsertAfter "Start time = " & CStr(sTime) & " seconds since 12:00:00" & vbCrLf
    .InsertAfter "Elapsed time = " & CStr((Timer - sTime) * 1000) & " milliseconds" & vbCrLf
    End With
    End With
    End Sub</code>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dufference in milliseconds (6.0)

    To measure small time intervals, you can use the Timer function. It returns the time since midnight in seconds as a value of type Single.

    Dim A As Single, B As Single, Diff As Single

    B = Timer
    ...
    ...
    A = Timer
    Diff = 1000 * (A -

    Please note that the smallest interval that you can measure is about 1/60 second, or 16 milliseconds.

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dufference in milliseconds (6.0)

    Sorry me... but very busy in this days...
    Naturally your code end explin work perfect!
    tks.

Posting Permissions

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