I am trying to prevent user from entering alphabets into TextBox1. I want user to only enter numbers. I have written following code in KeyUp event of the TextBox but the program does not run as intended. The compiler evaluates the MessageBox.show no matter what data is entered. If user enters a number, the MessageBox displays message and if an alphabet is entered, even then it gets executed. Could you please tell what is wrong with the following code?
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
If (Not Char.IsNumber(ChrW(e.KeyCode))) Then
MessageBox.Show("Enter only numbers")
End If
End Sub