Question : Restrict Textbox to Number and Decimal character only

I have a textbox on a windows form in a vb.net project I am working on in visual studio.   The value to be stored in the text box is a weight.   How can i restrict the user so that they can only enter numbers and a decimal point in the box?

Answer : Restrict Textbox to Number and Decimal character only

simple textbox code...........
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        ' Check if the typed character is a letter.
        If Char.IsDigit(e.KeyChar) = False And _
         Char.IsControl(e.KeyChar) = False Then
            e.Handled = True
        End If
        ' Check if the typed character is a period.
        If KeyAscii = 46 Then
            e.Handled = False
        End If
    End Sub
Random Solutions  
 
programming4us programming4us