FZ1
March 4th, 2006, 07:59 PM
Let me preface this by saying I am working on a homework assignment. However, I am asking for guidance not answers. I'm stuck here. I am taking VB.NET I and we are currently working on If/Else statements etc. We did a problem in class where we wanted to limit the data entry for a textbox to numbers only. No problem. The homework assignment has a similar problem except the textbox is a state abbreviation so no numbers or special characters are allowed. OK, I can code for the no numbers but can't figure out how to prevent special characters from being entered. I have looked on the web but the 1 instance I have found code that makes reference to ASCII characters which we have not gone over in class (other than to speak about what ASCII is) and there is not even a table in the book so I'm sure this is not the route we are supposed to take. Some other code I found is also way more advanced than the stuff we are doing. A girl from my class and I worked on this for about an hour an couldn't figure it out. Any insight is appreciated - I'm sure it's something simple and I'm overlooking it. Here is the portion of code I have written dealing with this problem:
Private Sub Cancelkeys(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles uiStateTextBox.KeyPress
If (e.KeyChar >= "0" And e.KeyChar <= "9") And (e.KeyChar <> ControlChars.Back) Then
e.Handled = True
End If
Obviously the logic rules out 0-9 and I've tried to exclude anything outside of <a & >z but that seems to allow everything. I'm officially with Jack, Sawyer and Kate - LOST!
Private Sub Cancelkeys(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles uiStateTextBox.KeyPress
If (e.KeyChar >= "0" And e.KeyChar <= "9") And (e.KeyChar <> ControlChars.Back) Then
e.Handled = True
End If
Obviously the logic rules out 0-9 and I've tried to exclude anything outside of <a & >z but that seems to allow everything. I'm officially with Jack, Sawyer and Kate - LOST!