Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set focus inside valid event?

Status
Not open for further replies.

kenndot

Programmer
May 15, 2001
316
US
I have this in the valid event...

IIF(date() - TTOD(this.value) > 7, Messagebox("INVALID DATE: Date Recieved cannot be more than 7 days prior to today.", 0, "Error"), this.value)

Then, I wanted the focus to stay on that field because I want the user to be forced to enter a valid value. When I put in .setfocus, I got an error saying you can't use that within a valid event. Can I do anything from that event to make the focus stay there?
 
Yes - Return 0 (zero). Since early FoxPro days, returning a numeric value in the VALID() would move the "focus" that many fields forward or backward - where zero stays put!

Rick
 
kenndot

It may not apply in this circumstance, but you may need to let your user escape from the control if they are unable to provide the correct data, otherwise they will be trapped forever.

The following example checks the length of a password.

In the .Valid() event of the control :-

IF LEN(ALLT(THIS.Value)) # 8
[tab]lnAnswer = MESSAGEBOX([Invalid password - try again?],;
[tab][tab]4 + 16 + 0,;
[tab][tab][Invalid password])
[tab]IF lnAnswer = 6
[tab][tab]RETURN .F.
[tab]ENDI
ELSE
[tab]RETURN .T.
ENDI


You then need to ensure they cannot perform certain tasks or actions if that has been the case.

The variable lnAnswer will provide you with an alternative means of knowing whether or not the data was valid.
HTH

Chris [pc2]
 
in the valid event
if lastkey() = 27 && escape pressed
return .t.
endif
Attitude is Everything
 
Have you tried RETURN .f. with the message in the ERROR event.

Otherwise I often use LOSTFOCUS for the valid so that I can pop up picklists and stuff like that.

Bill Couture
 
try

IF EMPTY(THIS.VALUE) OR THIS.VALUE>DATE()-7
RETURN 1
ELSE
Messagebox("INVALID DATE: Date Recieved cannot be More than 7 days prior to today.",0, "Error")
RETURN 0

ENDIF

 
Thanks guys, I didn't know about the 'return'...
 
you will notice the difference in the returns mention.

return .f. will produce a foxpro default wait window if invalid data, that will come up along with your message.

by returning 0 (zero) you maintain the focus and use your message but disable the default foxpro message Attitude is Everything
 
Interesting about the 0 will have to try that.

Bill Couture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top