By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,693 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,693 IT Pros & Developers. It's quick & easy.

Problem with GetTickCount

P: n/a
Hi

We're having some timing issues with one of our longer running software
programs.
I am trying to measure how many times my computer can loop through before
one millisecond has passed by and the result is ALWAYS different by a lot.
Almost like it's always a random number.

I'm using VB6.

Dim i As Long
Dim initial_count As Long

i = 0
initial_count = GetTickCount()

Do While GetTickCount() - initial_count < 1
i = i + 1
Loop

MsgBox "The number of loops in 1 millisecond equals " & i

would anyone have any idea why I get a different result everytime?
Thank you in advance

Private Declare Function GetTickCount Lib "kernel32" () As Long


Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This might help.

Dim i As Long
Dim initial_count As Long
Dim end_count As Long
Dim total As Long
Dim j As Long

initial_count = GetTickCount()

For i = 1 To 10000000

j = j + 1

Next

end_count = GetTickCount()
total = 10000000 / (end_count - initial_count)

MsgBox "The number of loops in 1 millisecond equals " & total
"farsad nasseri" <farsad na*****@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
Hi

We're having some timing issues with one of our longer running software
programs.
I am trying to measure how many times my computer can loop through before
one millisecond has passed by and the result is ALWAYS different by a lot.
Almost like it's always a random number.

I'm using VB6.

Dim i As Long
Dim initial_count As Long

i = 0
initial_count = GetTickCount()

Do While GetTickCount() - initial_count < 1
i = i + 1
Loop

MsgBox "The number of loops in 1 millisecond equals " & i

would anyone have any idea why I get a different result everytime?
Thank you in advance

Private Declare Function GetTickCount Lib "kernel32" () As Long

Nov 21 '05 #2

P: n/a
farsad nasseri wrote:
Hi

We're having some timing issues with one of our longer running software
programs.
I am trying to measure how many times my computer can loop through before
one millisecond has passed by and the result is ALWAYS different by a lot.
Almost like it's always a random number.

I'm using VB6.

Dim i As Long
Dim initial_count As Long

i = 0
initial_count = GetTickCount()

Do While GetTickCount() - initial_count < 1
i = i + 1
Loop

MsgBox "The number of loops in 1 millisecond equals " & i

would anyone have any idea why I get a different result everytime?
Thank you in advance

Private Declare Function GetTickCount Lib "kernel32" () As Long


I don't believe that you'll be able to use GetTickCount in this manner...
The resolution is not precise enough. According to the MSDN documentation
it's resolution is limited to the system timer - which can be obtained by
calling the GetSystemTimeAdjustment function.

If you need 1 ms resolution, then you should be using one of the high
performace timer functions... In particular you should look at the
QueryPerformanceCounter and QueryPerformanceFrequency, or you can look at
the multi-media timer functions.

By the way, this group is really a vb.net group. VB6 and earlier questions
should really be directed to microsoft.public.vb.* groups...

--
Tom Shelton [MVP]
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.