Results 1 to 3 of 3

Thread: Need Help PLEASE READ

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    8

    Exclamation Need Help PLEASE READ

    I’m working on a project and i need to use keychar.I need to check to make sure the first character is A-I and that the second Character is 1-9 and only allow that.
    Here's some code,

    Private Sub txtPlayerFireLocation_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtPlayerFireLocation.KeyPress
    If txtPlayerFireLocation.Text.Length = 1 Then
    If (e.KeyChar < "A" And e.KeyChar > "I") And e.KeyChar <> ControlChars.Back Then
    e.Handled = True
    End If
    End If

    If txtPlayerFireLocation.Text.Length = 2 Then
    If (e.KeyChar < "0" And e.KeyChar > "9") And e.KeyChar <> ControlChars.Back Then
    e.Handled = True
    End If
    End If
    End Sub
    End Class

    Please help

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Need Help PLEASE READ

    Try this
    Code:
        Private Sub txtPlayerFireLocation_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtPlayerFireLocation.KeyPress
    
            If txtPlayerFireLocation.Text.Length = 0 Then
                If (e.KeyChar >= "A" AndAlso e.KeyChar <= "I") OrElse (e.KeyChar >= "a" AndAlso e.KeyChar <= "i") Then
                    ' Accept
                ElseIf e.KeyChar = ControlChars.Back Then
                    ' Accept
                Else
                    ' Suppress
                    e.Handled = True
                End If
            ElseIf txtPlayerFireLocation.Text.Length = 1 Then
                If (e.KeyChar >= "0" AndAlso e.KeyChar <= "9") Then
                    ' Accept
                ElseIf e.KeyChar = ControlChars.Back Then
                    ' Accept
                Else
                    ' Suppress
                    e.Handled = True
                End If
            End If
    
        End Sub



  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    8

    Re: Need Help PLEASE READ

    Thanks this works fine.

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