954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Textbox Validation giving Error

I'm trying to validate my textbox so that the user must enter a Table Number between 1 and 20. The click event of the exit button checks this and if invalid input, displays a message box. It works for all numbers except 3-9 where it displays the warning even though it is in range. Anyone see where I'm going wrong?

Public Class Form1

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        If (txtTableNo.Text >= "1" And txtTableNo.Text <= "20") Then
            Me.Close()
        Else
            MessageBox.Show("Table Number must be between 1-20", "Warning")

        End If

    End Sub

    Private Sub txtTableNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTableNo.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
            AndAlso e.KeyChar <> ControlChars.Back Then
            e.KeyChar = ""
            Beep()

        End If
    End Sub

End Class
En-Motion
Light Poster
25 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

Changed:
If (txtTableNo.Text >= "1" And txtTableNo.Text <= "20") Then
ToIf (txtTableNo.Text >= 1 And txtTableNo.Text <= 20) Then

Works fine that way.

En-Motion
Light Poster
25 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You