Visual Foxpro and dotnet website development

Themed Image2
Blank The Current Field Using a Mouse Or Pen
(As pen based computing gains in popularity developers will encounter new problems. Doron Farber shows you how to blank an input field without a keyboard using his BlankFld function)

I specialize in developing applications for pen based computers, in conjunction with desktop computers. BlankFld, the function I will discuss here, allows a user to blank an input field in a pen-based computer environment where a keyboard isn't available. Or, in a desktop/ keyboard environment, the user can blank a field with a single keystroke or a mouse click.

The pen computer my clients use has a character-based recognition (OCR) capability that is provided by a product called Pen DOS. When Pen DOS is active, FoxPro recognizes pen actions, such as Dressing a control, just as it would a mouse click.

However, one problem needs to be solved in order to implement this capability. When the user presses a button, that button becomes the current object; VARREAD() no longer returns the name of the field were in and the user wants to blank.

Two memory variables can solve this problem. NowField establishes the current field name. NowObj keeps tracks of the current object number for each field. It assures that the cursor returns to the appropriate field. Both memory variables are initialized in the screen setup code.
The following functions are called via the WHEN clause in each field:
*==================================================
*** Function : FldData
*** Author : Doron Farber
*** Created : 01/06/94
*** Purpose : Get the current active field name, and current object number
*** Project : Common
*** Copyright : (c) The Farber Consulting Group, Inc.
*** Return Type : .T.
*** Notes : None
*==================================================
FUNCTION FldData
m.NowField=VARREAD() && Store GET variable name
m.NowObj=_CUROBJ     && Store object number, too
RETURN .T.
Otherwise, if you don't want to use a button to activate BlankFld or want to provide a keyboard alternative, you could use a hot key or menu shortcut to activate the BlankFld function. The hot key assignment might look like this:

ON KEY LABEL F5 DO BlankFld WITH VARREAD(),_CUROBJ

A menu shortcut might look like this:

DEFINE BAR 5 OF MyPop PROMPT "\<Blank Field" KEY F5, '[F5]';
SKIP FOR EMPTY(VARREAD()) OR _CUROBJ =0
.
.
ON SELECTION BAR 5 OF MyPop
DO BlankFld WITH VARREAD(), _CUROBJ

If you do it this way exclusively, you won't have to initiate NowField and NowObj as private memory variables.
The name of the field and the current object number will be passed as parameters. BlankFld can blank both numeric and character fields. To execute BlankFld via a button you need a GET similar to this for the button:

0 19,48 GET m.AnyMemVar FUNCTION '*N \<BLANK' ;
DEFAULT 1 SIZE 1,7 WHEN MDOWN() VALID BlankFld()

The "WHEN MDOWN()" in this GET prevents the button from being selected or pressed by any means other than the mouse.
Here is the BlankFld function:
***==================================================
*** Function : BlankFld
*** Author : Doron Farber
*** Created : 01/06/94
*** Purpose : To blank the current active field with one key
*** : Stroke
*** Project : Common
*** Copyright : (c) The Farber Consulting Group, Inc.
*** Project : Common
*** Parameter List :
*** m.WhichField : Gets the current field name via VARREAD()
*** m.WhichObj : Gets the current object number via _CUROBJ
*** Calling :
*** : a) ON KEY LABEL F5 DO BlankFld WITH VARREAD(),_CUROBJ
*** : b)0 19,48 GET m.AnyMemVar FUNCTION '*N \<BLANK' ;
*** : DEFAULT 1; SIZE 1,7 WHEN MDOWN() VALID BlankFld()
*** : c) Via a menu short cut
*** Return Type : None
*** Notes : None
***==================================================
FUNCTION BlankFld
PARAMETERS m.WhichField,m.WhichObj

* Next two lines are in case called from an OKL
SET TYPEAHEAD TO 0
PUSH KEY CLEAR

IF PARAMETERS()== 2
m.NowField = m.WhichField
m.NowObj = m.WhichObj
ENDIF

IF TYPE(EVALUATE('m.NowField')) ==’N’
STORE 0 TO (m.NowField)
ELSE
STORE SPACE(LEN(EVALUATE(m.NowField))) TO (m.NowField)
ENDIF
SHOW GET (m.NowField) ENABLE
_CUROBJ = m.NowObj

*** Next three lines are in case this routine was called from an OKL
CLEAR TYPEAHEAD
SET TYPEAHEAD TO 128 && or to whatever you like
POP KEY
RETURN .T.
Notice the code that prevents unwanted recursion of ON KEY LABEL (OKL) handlers (see the sidebar, "Prevent OKL Recursion Every Time"). Notice also how STORE statements stuff the new value into the GET variable for the field to be blanked. This way a named reference can be used instead of a macro expansion. If the "=" operator were used in place of STORE, you'd have to use a slower macro expansion.

&NowField = SPACE(LEN(EVALUATE(m.NowField)))

This is because named references are illegal on the left side of an assignment statement; they generate an "Unrecognized Command Verb" error.