Backspace in VFP

by Craig Bailey on April 25, 2005

in General Tech

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… read them below or add one }

Anonymous June 30, 2006 at 8:16 pm

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!!

Reply

Craig Bailey July 3, 2006 at 6:58 am

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

Reply

Leave a Comment

blog comments powered by Disqus

Previous post:

Next post: