Author: | David Manley / Tom Juncewicz / Michael D. Kersey |
Accessed: |
With the 16bit PB, you can only do this by using the timer function and the timer event or by using a C++ class or DLL. However, for 32bit, there's a nifty API function which does the same. It's called : sleep() ( who would have thought of that <G> ).
Local external function declaration subroutine sleep ( & long al_milliseconds ) & library "kernel32.dll" & alias for "Sleep"
David can be reached at DavidM@shoppingmall.co.nz
But then Tom came with a simple but effective way to do this in 16bit PB. It's very simple and it is actually working quite good!
Function f_sleep(int pi_seconds) defined as follows:
time lt_now lt_now = Now()
DO WHILE SecondsAfter(lt_now, Now()) < pi_seconds
Yield()
LOOP
Tom can be reached at tjunc@sprynet.com
After that came Michael D. Kersey, with an updated version of this function because the previous has a bug if the 'sleeping' time spans more than 1 day ( for instance start at 23.59:30 and sleep 45 secs ):
////////////////////////////////////////////////// // function gf_wait_seconds( long al_seconds ) // // Loops, Yield()'ing repeatedly until the // interval "al_seconds" passes. //////////////////////////////////////////////////
date start_date time start_time long days_to_wait long seconds_to_wait long seconds_per_day = 24 * 60 * 60
// Get the starting date and time. start_date = Today ( ) start_time = Now ( )
// Compute the number of days and seconds we must wait. days_to_wait = al_seconds / seconds_per_day seconds_to_wait = mod( al_seconds, seconds_per_day )
// Loop, Yield()'ing until that time has passed. DO WHILE ( DaysAfter ( start_date, Today() ) < days_to_wait ) OR ( SecondsAfter( start_time, Now () ) < seconds_to_wait )
Yield()
LOOP
RETURN
Michael can be reached at mailto:mdkersey@hal-pc.org