Another method is the
isnumeric
function, further reading
MSDN: IsNumeric[
^]
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not IsNumeric(e.KeyChar) Then
messagebox.show("Please enter a numeric value")
End If
End Sub
Updated thanks to Manfred seeing a problem in the code
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Char.IsNumber(e.KeyChar) OrElse Char.Equals(e.KeyChar, CType("-", Char)) Then
If TextBox1.Text.Length > 1 And Char.Equals(e.KeyChar, CType("-", Char)) Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub