-
Here is a simple way to make your program wait during an action.
First add a timer to your form. Call it Timer1. Sey its interval to 0 and its enabled property to FALSE.
Then add this subroutine.
------------------------------------------------------------
Public Sub Wait(seconds)
'-- Turn Timer On
Timer1.Enabled = True
'-- Set Timer Interval
Me.Timer1.Interval = 1000 * seconds
While Me.Timer1.Interval > 0
Do Events
Wend
'-- Turn Timer Off
Timer1.Enabled = False
End Sub
------------------------------------------------------------
Now when you want to use it just put in a line like this in a buttons Click() action.
Wait (5) '-- To Wait 5 seconds
If it doesnt work, check for spelling, i might have spelled something wrong. Hope it helps someone...
-
You can use API function Sleep for that.
-
Or make a loop with GetTickCount
-
You have to be careful about where your using the timer, its only accurate to 55 ms so its not useful for some applications.
-
hey, noone, are you 'no one' or 'noone'? just wondering if you're perfect or not =)
-
The timer control is based on the timer function which is not sensitive enough (updates about every 55ms). GetTickCount API updates exactly each ms.
-
How?
Whats an API, and how do i use GetTickCount?
-
Put this into your declarations:
Code:
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
API =Advanced Programmers Interface, But when we say An API, we mean a function (or sub) that we declare to use in user32.dll, kernel32.dll, gdi32.dll, advapi32.dll....I don't know them all. Gettickcount function should return a millisecond sensitive value for you.
-
Is that what API stands for? I always thought the 'A' stood for application, not advanced. Oh well, I could be(probably am) wrong.
Back on topic, I remember reading somewhere about an API Multimedia Timer that was also accurate to 1 ms, but whenever I used it my program just crashed. Does anyone else know what Im talking about?
-
Im not sure either what the A stands for, I've thought it was "Advanced", don't remember who told me that. I had one timer to but didn't like it. Evalution thing. I've had an vbx too.
-
API is 'Application Programming Interface'
Which is usually the published entry points to DLL files in a certain product.
Be careful with the Sleep API though because it will stall the app from redraws etc too which can look poor if part of you app gets temporarily covered. If timing to the Nth degree isn't so important, the while loop with DoEvents is usually fine.