Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

function to display a countdown

hello,
I'm using the Sleep function currently in some VB code so my program stops and waits until whatever time I specify for it to, but the problem with Sleep, is the user of my program has no idea how much time has elapsed. What I'd like to do is instead have a fuction that I can pass to it the time in seconds that I want to elapse, then that function displays a small window that shows the time counting down second-by-second in real time and also has a button that when clicked stops the countdown and executes the function.
Could anyone share with me the code that would acomplish this?
thanks in advance,
david
[645 byte] By [dgr7] at [2007-11-11 10:23:49]
# 1 Re: function to display a countdown
I use the following code:
Public Declare Function timeGetTime Lib "winmm.dll" () As Long

Public Sub TimeDelay(DelayAmount As Single)
'this sub simply provides a time delay for the declared amount, Note that this is not an accurate time delay
Dim StartTime As Single
DelayAmount = DelayAmount * 1000 'convert delay amount from seconds to milliseconds
StartTime = timeGetTime()
Do While timeGetTime() - StartTime < DelayAmount
DoEvents ' Yield to other processes.
DoEvents
Loop
End Sub
After that you might see about incorperating a "progress bar" into the code.
AM003295 at 2007-11-11 17:22:38 >
# 2 Re: function to display a countdown
thank you! your code was very helpful!
dgr7 at 2007-11-11 17:23:38 >