Home - Welcome - News - Blog archive - Sitemap - Store - Contact
NOTE: This is my backup blog - my main blog is now hosted at www.craigbailey.net (RSS feeds are unchanged)

Monday, April 25, 2005

Backspace in VFP

Thanks to Amit for alerting me to the fact that my backspace solution didn't work for the mouse event.

Turns out that the solution is still simple but involves using KeyPress aswell as Valid.

Simply add a new property (eg bAllowBackspace) to your textbox baseclass and then throw the follow code in KeyPress and Valid events

KeyPress()

LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode = 127 AND
This.SelStart < 1
This.bAllowBackspace = .F.
ENDIF

* other code etc

Valid()

IF This.bAllowBackspace = .F.
This.bAllowBackspace = .T.
RETURN .F.
ENDIF

* other code etc

2 comments:

Anonymous said...

This code works great. I'm glad it took me two seconds to google it. When you use this code you will get an "Invalid Input" error on your screen. If you want to suppress this message which is really just annoying, change the valid event to this

IF This.bAllowBackspace = .F.
This.bAllowBackspace = .T.
RETURN 0
ENDIF

You just return a zero instead of .F.
Here is the article on MS Knowledge base
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B90415
Thanks for the code Craig!!

Craig Bailey said...

Hi there,
Thanks for the tip regarding the return value. Nice one.
Craig