Displaying messages in FoxPro
Developers who have come into Visual FoxPro from other Windows tools tend to use the MessageBox dialog whenever they want to display a short text message. Visual FoxPro does offer other ways of getting a message to the user:
The Status Bar runs across the bottom of the screen, just above the Windows bar. Whilst you are developing it tells you which table's open, where you are in that table, and whether the record's locked. Users don't need to know this so you normally turn the status bar off at runtime:
Set Status Bar Off
but you can leave the bar on and control what's displayed there. As its name suggests, the Status Bar can be useful for keeping the user up to date with the system status:
Set Status Bar On
Set Message To 'There are ' + lcUnPaid + ' unpaid invoices.'
These commands display a small grey window in the upper right corner of the screen.
Wait Window "Here's a message"
The basic command will display a window and halt execution until the user presses a key or clicks the mouse. Some additional clauses make it more useful:
Wait Window 'Continue executing' Nowait
Wait Window 'Display for 5 seconds' Timeout 5
Wait Window 'Change position' At 10,10
Wait Clear && Release the window
A typical use for WAIT WINDOW ... TIMEOUT is to report progress through a long task. Use it to display messages for short periods at intervals through the task and clear them when the process completes. You could use a messagebox with its timeout feature but this takes more resources and doesn't always work if the user has assigned a sound scheme to the messages.
This command has been around since Fox for DOS so it does have a couple of foibles:
Not perhaps the obvious tool for short text messages but it does allow the user to scroll back through the messages. All you have to do is add your message to the box as a new line and make that the current value of the listbox.
.Value = lcMsg
The listbox will then scroll up as your messages appear. Very useful for showing the progress of this sort of housekeeping task.
Hints & tips
The textbox class in Visual FoxPro 9 has a new Autocomplete
property which shows the user the previous values that have
been entered in that textbox.