Displaying messages in Visual FoxPro

Developers who have moved into Visual FoxPro from other Windows development tools and languages tend to rely on the familar MessageBox() dialog whenever they want to display a short text message to the user. Visual FoxPro does offer several other ways of showing a warning or giving some information to the user:

  • Status bar
  • Wait Window
  • ListBox

Status bar

The Visual FoxPro Status Bar runs across the bottom of the screen, just above the Windows status bar. Whilst you are developing it gives you useful information such as which table is open, the position of the current record in that table, and whether or not that record is locked. Regular users don't need to know this degree of detail so it is usual to turn the status bar off at runtime. The early part of the program or the Init method of an application class will typically have a line of code:

Set Status Bar Off

Sometimes though it can be more useful to leave the bar on and then to control what is being displayed there. As its name suggests, the Status Bar can be useful for keeping the user up to date with the general state of the system:

Set Status Bar On
*-- Clear the status bar Set Message To 'There are ' + lcUnPaid + ' unpaid invoices.'

[Status bar in FoxBase+] Note that there is another very similar command:

Set Status On

This is a relic of the DOS versions of FoxPro and displays a status bar close to, but not quite at, the bottom of the screen. This bar shows much the same information as the modern-day status bar. Here's a screen shot of it in FoxBase+ from the late eighties.

If you see something like this in your application then you've missed the word 'BAR' from the command. An easy mistake to make.

Wait Window

The Wait Window is unique to the FoxPro family and, although it's very useful, it might be unfamiliar to some users.

[Wait Window in Visual FoxPro] 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 on screen' At 10,10
Wait Clear && Release the window

A typical use for the Wait Window with the timeout clause is to report progress through a long task.

Wait Window 'Copying customer file...' Timeout 0.1

Use it to display messages for short periods through the task and finally use a Wait Clear when the process completes. If the process hangs or fails for any reason then the last message will remain visible and this can be useful for tracing the cause of the fault.

You could use a regular Windows messagebox dialog with its timeout feature in a similar fashion but this takes more resources and doesn't always work if the user has assigned a sound scheme to the messages. The Wait Window can be set to flick on and off the screen in a tenth of a second so that the user just sees a blur of messages "Copying this", "Copying that", and so forth.

The Wait 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

[Visual FoxPro listbox showing progress messages] 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, especially if you use a two-column listbox and display a timestamp alongside each message in the list.

Related Items

Linking two listboxes in Microsoft Access

Linking parent and child listboxes in Microsoft Access so that selecting a new value in one listbox changes the values displayed in the other.

Read More

Multiple selections in a Visual FoxPro listbox

Allow the user to make multiple selections from a list using a FoxPro multiselect listbox

Read More