The GOFER UDF gofer()
Definition The gofer UDF allows the programmer to place
database information in picklist format in a FoxPro
browse window so a user can easily locate and accept or
reject items in the list. gofer() returns a .t. or .f.
reflecting the choice made.
Syntax gofer(), gofer(8,20,24,60).
Pass the browse window coordinates or a macro
containing them. gofer(&coord).
Use Use gofer() for database lookups. To retrieve a
customer number, allow the user to look up the name and
address using gofer() and the appropriate index. The
lookup database will be positioned correctly after the
lookup and if gofer() returns a .t., replace the
customer number with the lookup customer number.
Example 1 ON KEY LABEL F2 DO getcust
@ 1,1 SAY [Cust ID] GET m.custid
* gofer template
* current workarea and index
IF gofer(2,40,24,79) && lookup workarea and index
* current workarea and index
custid = lookupdbf->custid
WAIT [Would you like to add a customer?] WINDOW
* Note: current workarea and lookup WA may be the same.
Example 2 * gofer template
DO WHILE gofer(1,0,24,40)
REPLACE lookupdbf.fld WITH !lookupdbf.fld &&(Boolean fld)
Variables To fully define the picklist, 19 variables are required.
Required This includes the COORD parameter which is used to pass
the window coordinates. A template is provided both for
defaults and easing memory (yours) requirements.
KEY gofer() will position the record to the first
occurrence, if any, of the value provided in this memory
variable. A character type is required for a string
index, a numeric for a numeric index. Eg.
ALIAS Provide the name of the workarea containing the lookup
database. If the lookup workarea and the current workarea
are the same, use alias=ALIAS(); otherwise use, for
example, alias=[employee]. The work areas must already be
opened along with its indexes.
NORDER Enter the order for gofer() to use. I normally have two
indexes for the lookup database. The unique key that
the computer uses is normally order 1 and the lookup key
that the user uses (non-unique) is order 2 or greater.
To use the default order, set norder=0. gofer() resets
the order of the lookup database to its default before
LOVAL When a database is indexed, the browse command can
restrict access to the database by using the KEY option.
This is part of the browse command and is explained in the
FoxPro help manuals and help program. Loval requires
the same character type as the index type and is the
lower limit. Leave this as an empty string if lower
limits are not desired or remove the fragment KEY
loval,hival from the parameter variable discussed later.
HIVAL The upper limit corresponding to the loval mentioned
SUBSET This requires a .t. or .f. and is used to inform gofer()
when browse-key operations are required.
OK2EDIT To allow editing of all fields passed in the field list
discussed later, set OK2EDIT=1. To disallow all editing,
set OK2EDIT=0. To allow editing fields on an individual
bases, set OK2EDIT=1 and use the :R option in the field
KEYDELAY This value is used by the mouse for evaluating
double-clicks and by the character lookup feature when
typing in character strings for dynamic lookup. The
optimum value depends on two things: the speed of your
computer and your keyboard repeat rate. keydelay=.35
works fine for a 386-20 computer with a keyboard repeat
rate set at brisk.
COORD Pass the window coordinates for the initial browse screen
here. Eg. coord=[8,20,24,60]
TITLE Pass the title for the browse window here.
Eg. title=[ Select Code ]
FIELDS The fields and their parameters are passed here. Leave
fields empty to pass all fields. Enter the field names
separated by commas to use selected fields. Parameters
such as :R and :H are legal. For example:
or to pass all fields, FIELDS=
F1,F5 gofer() uses the hot keys F1, F5, and ^L as do many
applications. Rather than having to reissue hot key
commands, gofer() will handle that chore if hot key
definitions for F1 and F5 are stored in memory variables
F1 and F5. For example:
F5=[ON KEY LABEL F5 Do ]
&F5 &&(call hot key)
Window Color Colors for the various windows are passed in the
MSGCLR Color of the menu window on line 0.
HLPCLR Color of the help screen called with F1.
BRWCLR Color of the browse window.
EDTCLR Color of the edit window.
WRDCLR Color of the word-entry window.
Genpara The following are some of the general parameters that
can be passed for the browse window to use.
NOEDIT This parameter is required because keystrokes are used
NOAPPEND Normally this is required to control the data entry
NODELE May or may not be required.
KEY loval,hival May leave out if subset equals .f. Memory variables
loval and hival must be defined, however.
WIDTH This is a global restriction on field lengths. The
local : overrides this on a field basis.
TIMEOUT Limits the time the browse is enabled (before shutting
down) when left unattended.
LOCK This is another option you might want to add which is
not in the template provided.
Menu Bar The menu bar is located on line 0 of the screen. This
bar is mouse sensitive. The following items make up the
F1=HELP For help, click in this area and hold the left mouse
button down to view help.
F5=Search Click in this area. A string or numeric search is
allowed depending on the active index.
HOME=Top Click in this area. Go to first record (works with
END=Bottom Click in this area. Go to last record (works with
^L=Edit Click in this area. An edit screen is provided
containing the same fields as the browse window. Fields
may or may not be edited depending on the ok2edit status
and the :R field status.
ESC=Abort Click on this area to abort. gofer() returns a .f.
Pressing or ^Q also aborts.
ENTER=Select Click on this area to select. gofer() returns a .t.
Selection also can be made by pressing , ^W,
^End, or by double-clicking on the record in the browse
Sysmenu SET SYSMENU ON is the default for this FoxPro option.
When this is set ON, the user can access the SYSMENU bar
by double-clicking the right mouse button or by pressing
the ALT key. This is useful for modifying the browse
window (splitting, selecting browse or change mode, etc.)
and for searching and repeat searching. HINT: This sort
of searching is useful for searching non-indexed fields.
If a subset is used, this search method is limited to
Tips One slight side effect of trapping the left-mouse button
is noted. The clicking and dragging on the top border
of the browse window for moving the window and the lower
right corner of the window for resizing the window
sometimes fails if that action proceeds too rapidly.
When clicking and dragging in these two areas an almost
imperceptible delay before dragging will prevent this.
Template This is the template provided with gofer().
norder = 1
TITLE=[ Test ]
F1=IIF(TYPE([F1])#[C],[on key label F1],F1)
F5=IIF(TYPE([F5])#[C],[on key label F5],F5)
genpara=[NOEDIT NOAPPEND NODELE KEY loval,hival ;
WIDTH 16 TIMEOUT 600]
WAIT [True] WINDOW
WAIT [False] WINDOW