PDA

View Full Version : Can you "mask" data entry variables


ABC123

DON ERVIN
03-17-2005, 08:35 PM
I have a few fields on a form in which data is entered into a variable, rather than being entered directly into one of the fields of the primary table. Since field rules can only be set for "table" fields, I cannot limit the number of characters that a user can type into these fields.

In the Field Properties (Format) you can set the field width, and the string will be truncated to the correct length once the user presses the Enter or Tab key.

However ...... this is misleading to the user, who may enter 57 characters into the field, and then it is truncated to 30 ( or whatever Format is set to) once the Enter key is pressed. To save the user any frustration from having wasted keystrokes that end up being discarded, is there a way in Xbasic to attach an input limit to this field. I remember in the dBase IV days this was a simple affair. Although this is a minor problem, any ideas will be greatly appreciated.

Stan Mathews
03-18-2005, 04:34 AM
Use the candepart event for the variable's representation on the form.

if len(alltrim(var-"variablename))"30
ui_msg_box("Sorry","Entries over 30 characters are not permitted")
cancel()
end
end if

Tom Cone Jr
03-18-2005, 05:44 AM
Don,

In addition to Stan's suggestion there are two other possibilities that occur to me.

1) use the form's onKey event to monitor keystrokes entered in the field object. I believe it is possible to arrange a script there to determine whether the field object is in focus, and then to check the length of the input string as it's being built, keystroke by keystroke. Have not done this personally, but this is an area I'd consider worthy of investigation.

2) you could make the field object readonly. When the field object gets focus you could check the mode of the form. If it's in ENTER or CHANGE you could popup an xdialog and do the data entry there. While I'm not an expert on xdialogs I believe you can trap the keystrokes and check the length of the input string as the user works.

Let us know what you finally decide.

-- tom

Steve Dentler
03-18-2005, 06:02 PM
Yeah, I remember making a request for field length enforcement for variables about three years ago…guess it hasn’t worked its way to the top of the “to-do”list. In any event, you can do it with the OnKey event (it’s very tedious coding)…remember to allow the “Enter” and “Tab” keys and pretty much swallow everything else.

Don Ervin
03-18-2005, 09:26 PM
Thanks guys ... I am following up on the On Key suggestion (since the cutoff has to be done before the Enter or Tab key is pressed). I will post my solution here when I get it worked out.

Steve, I wonder why field length enforcement for variables wasn't put there in the very beginning. Your request must not have made it to the right person. Maybe someone that attends the Alpha Conference this year will do us a favor and mention it to the Alpha 5 folks ... shouldn't be that big of a deal to add. As I mentioned, it was built into the old dBase so I was really surprised to find out that in Alpha 5 you can type to infinity in a field variable.

Tom Cone Jr
03-19-2005, 06:22 AM
The "Features Wishlist" forum is designed to permit these types of enhancements to surface to Alpha's attention.

-- tom

Steve Dentler
03-19-2005, 06:31 AM
Here is a partial code from one of my OnKey events in a form. The first case "Kills" built-in AS shortcuts using the Control key combination. The next Case statement allows passing through the Enter, backspace, tab, and delete keys. Finally, the field length for the variable "M1" in enforced for 10 characters.

Select
case left(a_user.key.value,2) = "{^"
a_user.key.handled = .t.
Case a_user.key.value = "{Enter}" .or. a_user.key.value = "{Tab}" .or. \
a_user.key.value = "{Backspace}" .or. a_user.key.value = "{Delete}"
a_user.key.handled = .f.
Case f.active() = "M1"
if len(m1.text) = 10
a_user.key.handled = .t.
end if

Don Ervin
03-19-2005, 09:43 AM
Thanks, Steve ... looking at it I believe you have solved my problem.

Aren't user forums great !

Don