DjJohnny
asked on
Check To See If Decimal Key Was Pressed
Hi Experts,
I have a function in a module that will check to see if the user has pressed a number key or a some other keys. It seems to work but it will not see the user pressing the decimal key. I call this from the keypress event from a textbox and pass the KeyPressEventArgs.
This is the function
Thank You
John
I have a function in a module that will check to see if the user has pressed a number key or a some other keys. It seems to work but it will not see the user pressing the decimal key. I call this from the keypress event from a textbox and pass the KeyPressEventArgs.
This is the function
Thank You
John
Public Function CheckNumberKeypress(ByVal Input As KeyPressEventArgs) As Boolean
CheckNumberKeypress = False
If IsNumeric(Input.KeyChar) = True Then CheckNumberKeypress = True
If Input.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Back) Then CheckNumberKeypress = True
If Input.KeyChar = Microsoft.VisualBasic.ChrW(Keys.CapsLock) Then CheckNumberKeypress = True
If Input.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Decimal) Then CheckNumberKeypress = True
If Input.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then CheckNumberKeypress = True
End Function
This is The Call from the form:
Private Sub txtLinearFeet_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLinearFeet.KeyPress
If CheckNumberKeypress(e) = False Then
e.KeyChar = Nothing
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
FernandoSoto
Thank You. That worked like a charm.
John
Thank You. That worked like a charm.
John
Not a problem John, glad I was able to help. ;=)
You're probably wanting key code 0x2e which is the ASCII value of '.'. The Keys value for this is Keys.Delete, which you probably shouldn't use. I am not sure exactly what Keys is.