Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case e.KeyChar
Case "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "0"c, CChar(vbBack) '// your #'s and Backspace.
e.Handled = False '// allow.
Case "."c '// Decimal dot. allow only one.
If Not TextBox1.Text.Contains(".") Then e.Handled = False Else e.Handled = True
Case "-"c '// Minus/Subtract sign. allow only as first char.
If TextBox1.SelectionStart = 0 AndAlso Not TextBox1.Text.Contains("-") Then e.Handled = False Else e.Handled = True
Case Else
e.Handled = True '// block.
End Select
End Sub
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
ooh... totally forgot about the minus sign :P... Thanks for the collaboration
Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57