Textbox Validation giving Error

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2008
Posts: 17
Reputation: En-Motion is an unknown quantity at this point 
Solved Threads: 0
En-Motion En-Motion is offline Offline
Newbie Poster

Textbox Validation giving Error

 
0
  #1
Jan 29th, 2009
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?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Class Form1
  2.  
  3. Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  4. If (txtTableNo.Text >= "1" And txtTableNo.Text <= "20") Then
  5. Me.Close()
  6. Else
  7. MessageBox.Show("Table Number must be between 1-20", "Warning")
  8.  
  9. End If
  10.  
  11. End Sub
  12.  
  13. Private Sub txtTableNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTableNo.KeyPress
  14. If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
  15. AndAlso e.KeyChar <> ControlChars.Back Then
  16. e.KeyChar = ""
  17. Beep()
  18.  
  19. End If
  20. End Sub
  21.  
  22. End Class
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 17
Reputation: En-Motion is an unknown quantity at this point 
Solved Threads: 0
En-Motion En-Motion is offline Offline
Newbie Poster

Re: Textbox Validation giving Error

 
0
  #2
Jan 29th, 2009
Changed:
If (txtTableNo.Text >= "1" And txtTableNo.Text <= "20") Then
To
If (txtTableNo.Text >= 1 And txtTableNo.Text <= 20) Then
Works fine that way.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC