Company logo

FOXSTUFF

Advice, tips, techniques and downloads for Visual Foxpro developers.

Home | Contact

An easy way to add field-level help to your data-entry forms

Use this generic help panel to guide your users through your data-entry forms.

There are five obvious ways of providing help for data-entry operators in Visual FoxPro:

The first three are fine if the user only needs occasional help. But, because they require specific action on the user's part, they are less suitable for people who need constant guidance on every field.

Tooltips are usually a good option, but they offer only limited space for the help messages, they are distracting to experienced operators (you need to provide a way to turn them off), and they are of no help to non-mouse users.

As for status bar text, users don't always like having to shift their gaze from the form to the foot of the screen. Besides, the FoxPro status bar has an old-fashioned feel. Many developers switch it off to avoid users having to see record numbers, locking messages and the like.

Another option

We'd like to tell you about another option for field-level help — one which we have used successfully in several applications. It is completely generic and requires only a few of lines of code to implement. Our users like it because it is non-intrusive and does not demand any action on their part. Best of all, it does not require you to write help topics or keep track of context IDs.

To the user, the help text appears on a small panel at the foot of the data-entry form (see Figure 1). The text is displayed automatically as the user moves focus from field to field. We use a gentle color combination for the text — blue on gray is a favorite choice — as this makes it easy for users to ignore the message if they don't need to see it.

What's interesting about this technique is that the help text is not stored in the application. Nor is it in a help file. It is held in the field's Comment property within the database. The advantage of this is that the text can be maintained centrally. You only need one instance of the help message per field, and, if you need to change it, you only have to do so in one place.

Figure 1: A help message for the field in focus appears in a small panel at the foot of the form.

Implementation

To implement the technique, first add the help panel to your base data-entry form. The panel is simply a label with a different background color from the rest of the form. We generally set its BorderStyle property to Fixed Single and its WordWrap property to .T.

Next, add a custom method to the base form. Call it, say, ShowHelp. The method simply displays, in the label, whatever text is passed to it as a parameter, like this:

LPARAMETER cTextToShow
THIS.HelpPanel.Caption = cTextToShow

(HelpPanel is the name of the label in this example.)

The next step is to arrange for each field in the form to call the method and to pass it a parameter as it receives focus. The obvious place to do that is in the GotFocus event of the data-entry field's base class. The code might look like this:

THISFORM.ShowHelp ;
  (DBGETPROP(THIS.ControlSource,"Field","Comment"))

For this to work, the field's ControlSource must point to a field in a database table. The database field's Comment property should contain the help text; you enter this through the Table Designer. If you omit the text for a given field, no harm will be done — the help panel will simply remain blank.

In case you are wondering, DBGETPROP() is a built-in VFP function which, among other things, allows you to access any of the field or table properties for any database table. You could use it to get at the validation rules, the validation error messages, the format and input masks, and quite a lot more. See the VFP help file if you'd like to know more.

Finally, you need the following code in the base class's LostFocus event:

THISFORM.ShowHelp("")

This ensures that the help text disappears when a non-database control, such as a command button, receives focus.

And that's all there is to it. Assuming that all your data-entry forms and fields are derived from the appropriate base classes, you don't need to do anything else. Each time you drop a field on the form, the relevant help panel message will come right along.

Mike Lewis Consultants Ltd. January 1998.

More Visual FoxPro articles | Crystal Reports articles | Recommended books | Visual FoxPro consultancy | Contact us

FoxStuff is maintained by Mike Lewis Consultants Ltd. as a service to the VFP community. Feel free to download and use any code or components, and to pass around copies of the articles (but please do not remove our copyright notices or disclaimers).

The information given on this site has been carefully checked and is believed to be correct, but no legal liability can be accepted for its use. Do not use code, components or techniques unless you are satisfied that they will work correctly in your applications.

© Copyright Mike Lewis Consultants Ltd.