only numeric, backspace, delete key in a textbox vb6

I want to allow only numeric, backspace and the delete keys in my text box. I have not got the code for the backspace and delete key

for numeric i am using this code

private sub amount_keydown(keycode as integer, shift as integer)
 if keycode < 48 or keycode > 57 then
  keycode = 0
end if
end sub
Anthony MatovuBusiness Analyst, MTN UgandaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ascii codes (dec) for Backspace is 8 and for delete is 127. Maybe you can include them into the condition.
Try using a Masked Edit control, might make things simpler?
Try the following code:

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case Asc("0") To Asc("9"), 8 'Allow backspace
        Case Asc(
            ' Do nothing
        Case Else
            KeyAscii = 0
    End Select
End Sub

Keyascii value
backspace =8
delete = 46
numbers= 48 to 57


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial


Private Sub Texts_KeyPress(KeyAscii As Integer)

            Select Case KeyAscii
            Case 8,46, 48 To 57  ' BS, ,DELETE, 0 - 9
            Case Else      'Anything else
                KeyAscii = 0
            End Select
End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.