Thread: Keypress nest
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Keypress nest

Ok, had a chance to test it.

Change the function to:

Public Function chkinp(KeyAscii) As Long
Select Case KeyAscii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
KeyAscii = 0
End Select
chkinp = KeyAscii
End Function

Works fine, but you probably want to use Harald's class approach.

--
Regards,
Tom Ogilvy



"Tom Ogilvy" wrote in message
...
Untested, but I would suggest:

Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
KeyAscii = chkinp(keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
KeyAscii = chkinp(keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
chkinp = keyascii
End Function

--
Regards,
Tom Ogilvy



"Garry Jones" wrote in message
...
I received help here on how to check input in a text box and only allow
certain keys to be pressed.

It works, brilliant, now I want to use this as a seperate proceedure and
call it from several text boxes.

How to I send back the correct value from the check to "keypress"

I have tried this
__________________________________________________ ____________________
Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Function
__________________________________________________ ____________________

But this does not work, I am missing the exact description of how to
send back the value to the keypress check

Many thanks for any help.

Garry Jones
Sweden