|
-
May 14th, 2013, 01:00 PM
#1
Thread Starter
New Member
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
-
May 14th, 2013, 03:22 PM
#2
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
-
May 15th, 2013, 12:50 PM
#3
Thread Starter
New Member
Re: Need Help PLEASE READ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|