GetTickCount - How do you use it and how do you define it so that you CAN use it?
Printable View
GetTickCount - How do you use it and how do you define it so that you CAN use it?
GetTickCount() returns a Long value containing the number of milliseconds that Windows has been running. I believe the declaration is:
From memory, but I think its right...Code:Public Declare Function GetTickCount Lib "kernel32" () As Long
It is usually used to determine how much time has passed between two points in code:
Z.Code:Dim s As Long
Dim e As Long
Dim l As Long
s = GetTickCount()
DoSomething
e = GetTickCount()
l = e - s
How would I incorporate this into a loop to make things happen every 30 ticks?
Z.Code:Dim last As Long
last = GetTickCount()
While True
If last + 30 < GetTickCount() Then
last = GetTickCount()
'DoStuff
End If
Wend
This is the sub I have. When a command button is pressed, this runs. WBut, when I push it, my program freezes(as well as VB). Same thing happened with Zaei's code.
Code:Public Sub Run()
Dim T As Long
Do Until DONE = True
T = GetTickCount + 30
If GetTickCount >= T Then
MouseMove
DoEvents
End If
Loop
End Sub
Move the DoEvents out of the If Statement.
You are setting T at every loop iteration, which means that the If statment will NEVER fire, because T is ALWAYS 30 greater then GetTickCount. ONLY Set T inside the If statment.
Z.