Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetTickCount

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
I have created an application that uses the GetTickCount function, of the windows API, to make the application pause for a number of seconds. It works fine under windows 2k, but when i run it under WinNT it doesn't seem to pause(ie ignores the GetTickCount bit). Is there any reason for this?

my code is:
Private Declare Function GetTickCount Lib "kernel32" () As Long

Function pause()
Dim starttime as long
Dim endtime as long

starttime = GetTickCount
endtime = 0

'wait 5 seconds
Do Until (endtime - starttime) > 5000
endtime = GetTickCount
Loop

End function

Neil
 
I have just run the app on the WinNT machine again and it seems that GetTickCount returns a negative number. I'm guessing it shouldn't be doing that...


 
According to this
GetTickcount returns to 0 every 49 days BUT at that time the Tick count is over 4 billion... indicating that an unsigned Long is being returned.
Try this.
starttime = GetTickCount
endtime = startTime

'wait 5 seconds
Do Until (Abs(endtime - starttime)) > 5000
endtime = GetTickCount
Loop
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Ah, that seems to work! But weirdly enuf I need to do:

starttime = abs(gettickcount)
endtime = 0

do until (endtime-starttime) > 5000
endtime = abs(gettickcount)
loop

Thanks!! :-D
 
Hey, here's another idea...

Instead of putting in a loop and checking the tick count, you could just use

Declare sub Sleep Lib "kernel32" (byVal dwMilliseconds as Long)

whenever you want to pause for any length of time use

Sleep 5000

Using this instead of a loop prevents other problems too... I hope you see this soon. If you are going to keep the do until ... loop, put in a doevents inside the loop to free up other events!

Hope this helps!

Tuna


 
It also causes it's own problems, since it doesn't just pause your application, it stops it dead in it's tracks. As long as one is aware of that fact, I'd agree that sleep can be a good option.
 
thanks for the sleep function, I will use that instead, as like you said, it was pausing the application and made it impossible to debug when any problems occured.

Thanks Again!

NEil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top