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 2

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.
 
Ok, did not know about SETting ESCAPE OFF. Will try that.

I saw about property in the Hacker's Guide, but so far as I know, there is no PROPERTY function in FPM 2.6b.
 
Who was talking about a property function? The command button has a property called "Cancel":
1745299350568.png
That's a visual control class. I doubt you have that in legacy FoxPro.
It's also a standard of MS Windows, the Cancel and OK buttons of forms.

So, that's all about Visual FoxPro. And, by the way, the default hotkey for Cancel is ESC, and still works with SET ESCAPE OFF. What you set of is ESC interrupting the running code. And that should work in all FoxPro versions. What I think is only working in Visual FoxPro is that clicking the button with its Cancel property set .T. causes LASTKEY() to become 27, even if you didn't actually pressed ESC. That's what alloes the LASTKEY() trick both when you actually press ESC or when you click the button.
 
Last edited:
Ok, until I figure out why ESC is acting "erratically" in my code, I am going to use the CHR(1) method to CANCEL edits. Regardless, this change (a huge improvement) solves many of the problems I have been having with canceling edits. At least now my code is not likely to break when editing it. I am the only user.
 

Part and Inventory Search

Sponsor

Back
Top