Discussion:
How to disable the delete-button (keyascii=46) in a textbox in vb6
(too old to reply)
Catharinus
14 years ago
Permalink
Hello my friends
I have a texbox in which I want to insert, delete or update text.
I want to disable the keyascii = 46 (the delete-button)

I use the subrouitine Text1_keypress (keyascii as integer)
It contains, among more things,. the following code:

select case keyascii

'case 9, 13, 27
keyascii = 0
case 8
code for the backspace key
else
text1.text=text1.text & chr(keyascii)
end case

But the keyascii = 46 does not work in this.
Any idea??

Thanks
Catharinus
Deanna Earley
14 years ago
Permalink
Post by Catharinus
Hello my friends
I have a texbox in which I want to insert, delete or update text.
I want to disable the keyascii = 46 (the delete-button)
I use the subrouitine Text1_keypress (keyascii as integer)
select case keyascii
'case 9, 13, 27
keyascii = 0
case 8
code for the backspace key
else
text1.text=text1.text& chr(keyascii)
end case
But the keyascii = 46 does not work in this.
Any idea??
Ignore your sample code being invalid, you should be checking for the
control character keys in the KeyDown event and check for the
appropriate KeyCode.
If it's one you want to block, just set it to 0 and leave the rest to
the control.
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Catharinus
14 years ago
Permalink
...
Thanks

Doing so causes the deletion of part of the text in the textbox
Any idea?

Catharinus
Deanna Earley
14 years ago
Permalink
...
Doing what?
This works for me to drop delete and backspace.

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then KeyCode = 0
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then KeyAscii = 0
End Sub
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Catharinus
14 years ago
Permalink
...
I am sorry. You're right, It looks I am doing something wrong.
Thanks
Henning
14 years ago
Permalink
...
I am sorry. You're right, It looks I am doing something wrong.
Thanks

Dumb? question, have you set the Form KeyPreview property to True?

/Henning

Loading...