Results 1 to 2 of 2

Thread: Limiting letters and numbers in a text box.

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    33

    Post

    what if in a text box i dont want any numbers to be typed in and only 2 letters??? how can i do this??

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    I'm not sure what you are asking about, but if you don't want numbers and you allow user to type any two letters then use this:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If IsNumeric(Chr(KeyAscii)) Then
            KeyAscii = 0
        End If
    End Sub
    Also set TextBox's MaxLength property to 2
    ~~~~~~~~~~~

    Or if you know what two letters you want the user to enter (for example if you want them to type C for Credit and D for Debit) and you want the user to enter only one letter on a time then use this:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If (Chr(KeyAscii)) <> ["Enter Your First Character"] or (Chr(KeyAscii)) <> _
        ["Enter Your Second Character"] Then
            KeyAscii = 0
        End If
    End Sub
    And set MaxLength Property to 1
    ~~~~~~~~~~~~~~~~~~

    ------------------
    Visual Basic Programmer (at least I want to be one)
    ------------------
    PolComSoft
    You will hear a lot about it.

    [This message has been edited by QWERTY (edited 12-04-1999).]

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