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:

  • Status bar
  • Wait Window
  • ListBox

Status bar

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.'

Wait Window

[Wait Window]

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:

  • The timeout is in seconds - not the usual milliseconds
  • The position is in rows and columns - not pixels or twips

ListBox

[Progress messages displayed in a FoxPro listbox]

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.

With ThisForm.lstProgress
   .AddItem (lcMsg)
   .Value = lcMsg
EndWith

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.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map