Getting ASCII code on KeyPress event

S

Seth

I want to prevent characters other than the following from being entered into
a text box:

‘0’ to ‘9’
‘A’ to ‘Z’ (upper case only)
‘.’ (full stop)
‘-‘ (minus sign)

I have tried using the KeyPress event and setting KeyCode to null but there
is no KeyCode for ‘.’ or ‘-‘. Also it dose not differentiate between upper
case and lower case.

Can I retrieve the ASCII value of the character entered within the KeyPress
event procedure?


Cheers,
Seth
 
D

Dirk Goldgar

Seth said:
I want to prevent characters other than the following from being
entered into a text box:

'0' to '9'
'A' to 'Z' (upper case only)
'.' (full stop)
'-' (minus sign)

I have tried using the KeyPress event and setting KeyCode to null but
there is no KeyCode for '.' or '-'. Also it dose not differentiate
between upper case and lower case.

Can I retrieve the ASCII value of the character entered within the
KeyPress event procedure?

Are you sure you've been looking at the KeyPress event and not the
KeyDown event? The KeyPress event procedure receives an argument,
KeyAscii As Integer, which is the ASCII value of the key that was
pressed. Note that non-ASCII keys will fire KeyDown and not KeyPress.
 
Top