Backspace in VFP

B

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

4 comments

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

  • 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 thisIF This.bAllowBackspace = .F.This.bAllowBackspace = .T.RETURN 0ENDIFYou just return a zero instead of .F. Here is the article on MS Knowledge basehttp://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B90415Thanks for the code Craig!!

About Craig

I'm the co-host of HubShots and the CEO of XEN - helping mid-large B2B companies with their digital marketing and lead generation.

Craig Bailey

Archives

Posts