jalo Posted September 30, 2005 Posted September 30, 2005 i am trying to enable specific key presses. i am having trouble with the period key and the decimal key. i tried this Asc(e.KeyChar) = Keys.Decimal Asc(e.KeyChar) = Keys.OemPeriod but it doesn't seem to work... the first line does not respond to any key press, while the second line responds to pressing "n" lowercase... i am puzzled... anyone have an idea? Quote
bri189a Posted September 30, 2005 Posted September 30, 2005 I don't understand what you are trying to do - it looks like you're trying to set the key that was was pressed from the event args - which you can't do. If you're simply trying to test if the 'period' was pressed you should: if(Convert.ToInt32(e.KeyChar)==Convert.ToInt32('.')) { //Do whatever } If Convert.ToInt32(e.KeyChar) = Convert.ToInt32("."c) Then 'Do something End If Quote
jalo Posted October 2, 2005 Author Posted October 2, 2005 i was trying to check whether a keypress is a period (in order to allow that keypress). thanks for the tip - works for me! :-) Just wodering about the syntax though - could you explain the ("."c) - i am puzzled by the c.... If Convert.ToInt32(e.KeyChar) = Convert.[color=Red]ToInt32("."c)[/color] Then 'Do something End If Quote
Leaders snarfblam Posted October 2, 2005 Leaders Posted October 2, 2005 The c indicates that the value is a Char constant. A Char is a value type that holds a single character (sort of like a 1-character fixed length string). Just like the "r" in 1.0r indicates that a value is a double, the "c" in "."c indicates that the value is a Char (as opposed to a string). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.