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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Valid event fires when clicked outside of test box 1

ravicoder

Programmer
Apr 29, 2006
34
IN
Hi all

I have a data entry form with some text fields and <save> and <cancel> buttons. My issue is that when focus is on a text box and cancel button is clicked the valid event of the text box fires and user has to click on ok on the messagebox that appears and then again click on cancel button

sample code

rkey = Readk()

If _rkey()
If Not Empty(This.Value)
helpselected = .F.
helpcode = ''
helpname = ''
=namehelp("Centres Master",'master_centres','centre_code','centre_name',Allt(This.Value))
If helpselected
This.Value = helpname
Thisform.centre_code = helpcode
thisform.getstate()
thisform.Refresh()
Endif
Else
Thisform.centre_code = ''
Endif
Endif
end of sample code

is there any way I can avoid this?

thanks in advance
 
I don't quite understand your sample code but I am assuming you are trying to validate the entry in this textbox and show the message if there is no value. Do it on LostFocus() and return -1 so the cursor stays in the textbox. I don't really like this because the user will have to enter something, otherwise they will not be able to leave the textbox. You can do validation on command button OK or SAVE instead of on VALID(), this way, if the user enters CANCEL, it doesn't matter what in the texbox
 
Right now i have no access to my development-environment. But check if the MOUSEDOWN-Event in your CANCEL-Button fires earlier as the VALID-Event.
 
See Hacker's Guide last paragraph of using LASTKEY() in the valid event code. That's a standard that should be known by all foxpro developers.
 
See Hacker's Guide last paragraph of using LASTKEY() in the valid event code. That's a standard that should be known by all foxpro developers.
Thanks for posting that - It elegantly solves a problem I have had for decades - Now I can throw away my clunky solution.

However, it does not tell me where to and how to add the escape code to the buffer without causing an *** INTERRUPTED *** program error.

But, if I stuff the buffer with CHR(1) in WHEN then check for LASTKEY() = 1 in VALID, the cancel button cancels edits as expected.
 
Last edited:
On top of the LASTKEY() solution you need to have a few standards. That is SET ESCAPE OFF and set the Cancel property of the Cancel button to .T., so a) ESC triggers it and b) clicking it triggers ESC. The Hacker's Guide tells oyu about the Cancel property on the same page.
 

Part and Inventory Search

Sponsor

Back
Top