CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Posts
    13

    constrain user keyboard?

    how can i constrain the user keyb to only letters and numbers

    thnks


  2. #2
    Join Date
    Aug 2000
    Location
    KY
    Posts
    766

    Re: constrain user keyboard?

    Paste this code in your Keypress event

    [vbocde]
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    KeyAscii = OnlyRealText(Keyassic)
    End Sub

    Public Function OnlyRealText(Key As Integer) As Integer

    Select Case Key
    Case 48 To 57 'Numeric
    OnlyRealText = Key
    Case 65 To 90 'UpperCase Letters
    OnlyRealText = Key
    Case 97 To 122 'LowerCase Letters
    OnlyRealText = Key
    Case 8, 13 'Backspace and Enter
    OnlyRealText = Key
    Case Else
    Key = 0
    End Function
    [/vbcode]



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