Results 1 to 5 of 5

Thread: [Resolved] Preventing Keystrokes

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Resolved [Resolved] Preventing Keystrokes

    Allright, Im programming a MMORPG, I dont want Numbers Nor Spaces in the Name. So, I set this up;

    Code:
    Private Sub txtName_KeyPress(KeyAscii As Integer)
    Dim ch As String
          
        ch = Chr$(KeyAscii)
        If Not ( _
            (ch >= "a" And ch <= "z") Or _
            (ch >= "A" And ch <= "Z") _
        ) Then
            ' Cancel the character.
            KeyAscii = 0
        End If
    End Sub
    Works exactly how I wanted,But Wait, I can't backspace now. So, Does anyone know how I could make it allow the backspace key?
    Last edited by wisefire; Sep 21st, 2007 at 09:59 PM.

  2. #2
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Preventing Keystrokes

    Here ya go.

    Code:
    Private Sub txtName_KeyPress(KeyAscii As Integer)
    Dim ch As String
    if not keyascii=vbkeyback then
        ch = Chr$(KeyAscii)
    
        If Not ( _
            (ch >= "a" And ch <= "z") Or _
            (ch >= "A" And ch <= "Z") _
        ) Then
            ' Cancel the character.
            KeyAscii = 0
        End If
    End Sub

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Preventing Keystrokes

    You can see my post in this
    with proper coding and easy to modify to suit your need.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Preventing Keystrokes

    Quick! Thank You!!!

  5. #5
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Preventing Keystrokes

    If this thread is resolved pull down your thread tools and mark it resolved.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

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