Link to home
Start Free TrialLog in
Avatar of DjJohnny
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

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of drichards
drichards

The Decimal is probably the keypad '.' key when the keypad is in a certain mode.

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.
Avatar of DjJohnny

ASKER

FernandoSoto

Thank You. That worked like a charm.

John
Not a problem John, glad I was able to help.  ;=)