Example, in the valid you validate an account, ie if it exists in the chart of accounts, you just return 1 and go to lostfocus. If it does not exist, you display an error message and return 0
I'l give a better for instance. Just assume you have a form with a textbox for inputting the account code, another textbox where you show the account description (after you found it of course !!) and a command button that calls a lookup form (with a lookup grid)
The objects names are: txtAccount, txtAccDesc, btnAccLkUp
I usually use this code:
** Valid event txtAccount
local cAccount
** the next three lines bypass the validation when you click on the lookup button
if empty(this.value) return 1 endif
cAccount = str(val(this.value),6) && numeric code, six digits maximum
set near off
if seek(cAccount,"acchart","accnum") this.value = acchart.accode return 1 else this.value = space(6) messagebox("INVALID ACCOUNT",48,"ATTENTION") return 0 endif
** lostfocus event txtAccount
thisform.cAccount = str(val(this.value),6) thisform.cAcDesc = acchart.acdesc thisform.txtAccDesc.value = thisform.cAcDesc
**click event btnAccLkUp
thisform.seeaccounts()
** form seeaccounts method
** note: the AccLkUp form does not close when a selection is made (it is not released). You should call its hide method, instead. Release is made after you read the values.
do form AccLkUp with 1 name oAccounts linked
this.cAccount = oAccounts.cAccount thisform.cAcDesc = oAccounts.cAcDesc
oAccounts.release oAccounts = NULL
this.txtAccDesc.value = this.cAcDesc
with ThisForm.txtAccount .value = thisform.cAccount .setfocus endwith
Check these two articles to see how to use a grid as a picklist, if you are interested.
http://www.utmag.com/April2002/Page6.asp http://www.utmag.com/June2002/Page32.asp
If you'd rather call the lookup form directly by hitting a function key, for example F10, you would do so using the keypress method of the textbox, like so:
if nKeyCode = -9 && F10 key thisform.seeaccounts() endif
The first three lines in the Valid event would have to be changed to these:
if empty(this.value) or lastkey() = -9 && mouse clicked or F10 key pressed return 1 endif ******************************************************************** You could argue that the lostfocus code above could be placed in the valid event, which is true. However, what if you wanted to call another form, or a method in your form, after you validated input ? You would most certainly use the lostfocus event for that. In addition, by just atomizing the validation code to its minimum, it is clearer to understand and easier to debug.
I hope it helps
Best regards
Rafael Copquin Estudio Copquin Southern Software Services www.copquin.com.ar
----- Original Message ----- From: "Chuck Urwiler" <chuck (AT) eps-software .DOT com> To: "ProFox Email List" <profox@leafe.com> Sent: Friday, October 31, 2003 10:16 AM Subject: RE: Restrict Textbox Values?
You've made my point for me. I think that anyone who hasn't used anything before VFP is NOT likely to use Valid because it's not very clear when it occurs, whereas LostFocus is clear (and consistent with other products) about when it occurs.
Question: since you use Valid, then what do you use LostFocus for? From what you've said here, you're sometimes putting code in both the Valid and LostFocus. Why do that?
-Chuck Urwiler, MCSD, MCDBA http://www.eps-software.com
©2003 Rafael Copquin |