Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB6 - Validation (VB6)

    Hi

    I need a piece of code so that a text box will only accept the values A thru Z or ^ or hyphen. It needs to accept these in any combination. In my effort I can get bits of it to work separately, but not altogether.

    Thanks very much

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: VB6 - Validation (VB6)

    You can use the On Key Press event of the text box to check the input:

    Private Sub txtInput_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 45, 65 To 90, 94
    ' allowed
    Case Else
    ' not allowed
    KeyAscii = 0
    End Select
    End Sub

    This will only allow upper case letters (Ascii 65 to 90) plus a hyphen (Ascii 65) and a "hat" ^ (Ascii 94). If you also want to allow lower case letters (Ascii 97 to 122), use

    Case 45, 65 To 90, 94, 97 To 122

  3. #3
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - Validation (VB6)

    Hi

    Yes. This works fine. Thanks very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •