# Thread: Dufference in milliseconds (6.0)

1. ## 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)
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. ## 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. ## 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. ## 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. ## 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
•