March 4, 2009

Vb.net - Enter only Numeric Values

Private Sub txtbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtbox1.KeyPress
e.Handled = OnlyNumeric(e.KeyChar)
End Sub

Public Function OnlyNumeric(ByVal Value As String) As Boolean
OnlyNumeric = True
If (Microsoft.VisualBasic.Asc(Value) > 47) And (Microsoft.VisualBasic.Asc(Value) < 59) Then
OnlyNumeric = False
End If
If (Microsoft.VisualBasic.Asc(Value) = 8) Then
OnlyNumeric = False
End If
End Function

No comments:

Post a Comment