In VB you can allow a textbox to accept numbers only by placing some codes in the KeyPress event of the textbox. The e argument has a property called KeyChar that you can use to read a character from keyboard. You will use Asc(char value) or AscW(char value) to convert the character to integer code. Key 0 to 9 is equivalent to code 48 to 57.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Then ' accept numbers only
Beep() 'sound effect
e.Handled = True ' do not accept any key other than numbers
Posted by: Lavy | post date: 02-10-2013 | Subject: VB.NET Programming Language
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: