Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
WAIT is a simple little command, but with nice effect. Its primary mission in life is to display a message. By default, a WAIT WINDOW command appears in the upper right corner of the active screen, below the toolbars, while a plain WAIT is displayed in the current output window.
WAIT [ CLEAR ] | [ cMessage ][ TO cResponse ]
[ WINDOW [ AT nRow, nColumn ] [ NOWAIT ] [ NOCLEAR ] ]
[ TIMEOUT nTime ]
Parameter |
Value |
Meaning |
CLEAR |
Clears any existing WAIT WINDOW. Cannot be used with any other keywords or arguments! |
|
cMessage |
Character |
The message to be displayed. Multiple lines can be specified by separating strings with carriage returns (CHR(13)'s). More than 254 characters generates error 1903, "String too long to fit." |
Omitted |
Display "Press any key to continue..." |
|
Empty String |
Show the cursor, blinking, at the last output location, unless you have SET CURSOR OFF. |
|
cResponse |
Character |
Receives a one-character alphanumeric response. Blank is returned for nonprintable characters or mouse clicks. The specified memory variable is created if it doesn't exist. If it does exist, its type is changed to character, if necessary, and its value is overwritten. |
nRow |
Numeric |
The row where the window should appear. The row number is based on the screen font (see WFONT()). Numbers less than 0 are ignored. |
nColumn |
Numeric |
The column where the window should appear. The column number is based on the screen font (see WFONT()). Columns less than 0 are ignored. |
NOWAIT |
Continues processing immediately. |
|
NOCLEAR |
WAIT WINDOW remains until another WAIT WINDOW command or WAIT CLEAR is issued. Without this clause, the window clears when a keystroke or mouse click is received. |
|
nTime |
Numeric |
The time to wait in seconds before continuing processing. Ignored if NOWAIT is specified. |
Note that CLEAR and NOCLEAR are not a pair, as the Help would have you believe. CLEAR must be used alone to clear an existing window; any other use results in a syntax error. NOCLEAR is new to Visual FoxPro—it keeps a window on the screen even if a keystroke is pressed.
The many clauses of WAIT that were added over the years can lead to some commands that look like they should work, and don’t cause an error message, but don’t give the expected response. For example,
WAIT WINDOW NOWAIT "Processing..." TIMEOUT 30
might be interpreted as “Display this message, let me continue processing, and then clear the message after 30 seconds.” In fact, the TIMEOUT clause is ignored if NOWAIT is specified, and the message clears only if a keystroke is pressed or a WAIT CLEAR command is issued.
WAIT is getting dated. For input, consider instead a MessageBox or custom form. To keep the user informed of processing status, a custom form with the new ProgressBar control is more informative and more standard. Finally, look at the many options to update messages on the application status bar as well. WAIT WINDOWs give away that a FoxPro app is running—not necessarily a bad thing, but a non-standard interface that could confuse new users.
WAIT "" produces a blinking cursor in the screen or current output window. WAIT WINDOW "" does the same—where's the WINDOW? There ain't one. |
WAIT "" NOWAIT immediately executes the next command, with no display as you might expect. However, WAIT "xxx" NOWAIT leaves the cursor blinking on the "xxx" message and needs a key to return control to the program, ignoring the NOWAIT clause. In fact, even WAIT NOWAIT with no string waits. We hardly ever use NOWAITs without WINDOWs, because the window, particularly with the AT clause, is so cool. But if you're going to use it (consider using ? instead), or are porting code that uses it, don't expect it to NOWAIT just because you told it to. |
WAIT WINDOW "Sorry, Dave, I can't do that." NOWAIT NOCLEAR