SLEEP
Topic group Related topics Example
Pauses a program for a specified interval or until a specified time.
Syntax
SLEEP
<seconds expN> |
UNTIL <time expC> [,<date expC>]
<seconds expN>
The number of seconds to pause the program. The number must be greater than zero and no more than 65,000 (a little over 18 hours). Fractional times are allowed. Counting starts from the time you issue the SLEEP command.
UNTIL <time expC>
Causes program execution to pause until a specified time (<time expC>) on the current day. If you also specify <date expC>, the program pauses until the time on that day. The time and date dBASE Plus uses are the system time and date. You can set the system time with SET TIME and the system date with SET DATE TO. If the time has already passed, SLEEP UNTIL <time expC> has no effect.
The <time expC> argument is a 24-hour time that matches the format returned by the TIME( ) function. A typical format for <time expC> is "HH:MM:SS". The delimiter is conventionally a colon but can be changed through the Regional Settings in the Windows Control Panel. The time string must include the seconds.
<date expC>
An optional date until which the program is to pause. The <date expC> argument is a character expression (not a date expression) that represents a date in the current date format; it would match the string returned by the DTOC( ) function. For example, if SET DATE is AMERICAN, the format would be "MM/DD/YY".
If the date has already passed, SLEEP UNTIL <time expC> [,<date expC>] has no effect. If you want to specify a value for <date expC>, you must also specify a value for <time expC>.
Description
Use SLEEP to pause a program either for <seconds expN> seconds or until a specified time (<time expC>). The specified time is the same day the program is running unless you specify a date with <date expC>. If SET ESCAPE is ON, you can interrupt SLEEP by pressing Esc.
Note
If SET ESCAPE is OFF, there is no way to interrupt SLEEP. However, you can use Ctrl+Esc and Alt+Tab to switch to another Windows application, or Alt+F4 to exit dBASE Plus.
Although SLEEP can generate a pause from the Command window, programmers use it primarily within programs. For example, you can use SLEEP to generate a pause between multiple displaying windows or to allow a user to read a message on the screen or complete an action. Pauses are also useful when you need to delay program execution until a specific time.
While SLEEP is active, dBASE Plus is considered busy; that is, busy sleeping. Program execution is suspended, keystrokes go into the typeahead buffer, and dBASE Plus does not respond to events like mouse clicks or timers. If you want an event to occur at a specified time without putting dBASE Plus to sleep, use a Timer object.
SLEEP is an alternative to using a DO WHILE loop, a FOR loop, or WAIT to generate pauses in a program. SLEEP is more accurate than using loops because it's independent of the execution speed of the system. You can also use INKEY(<expN>) if you want the user to be able to interrupt the pause and continue with program processing.