VB.net Need Text Box to Only Accept Numbers

Posted by Rico Jackson on Stack Overflow See other posts from Stack Overflow or by Rico Jackson
Published on 2012-04-02T01:09:09Z Indexed on 2012/04/02 5:30 UTC
Read the original article Hit count: 190

Filed under:
|
|

I'm fairly new to VB.net (self taught) and was just wondering if someone out there could help me out with some code. I'm not trying to do anything to invovled, just have a textbox that takes numeric value from 1 to 10. I don't want it to take a string or any number above 10. If some types a word or character an error message will appear, telling them to enter a valid number. This is what I have, obviously it's not great as I am having problems. Thanks again to anyone who can help.

 If TxtBox.Text > 10 Then
        MessageBox.Show("Please Enter a Number from 1 to 10")
        TxtBox.Focus()
    ElseIf TxtBox.Text < 10 Then
        MessageBox.Show("Thank You, your rating was " & TxtBox.Text)
        Total = Total + 1
    ElseIf IsNumeric(TxtBox.Text) Then
        MessageBox.Show("Thank you, your rating was " & ValueTxtBox.Text)

    End If
    ValueTxtBox.Clear()
    ValueTxtBox.Focus()

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about textbox