CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jan 2006
    Location
    Cincinnati
    Posts
    24

    Entry exclusion logic

    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:

    Code:
    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!
    Last edited by FZ1; March 5th, 2006 at 10:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured