Results 1 to 2 of 2

Thread: Validation

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    San Dimas Ca,
    Posts
    4

    Post

    I am trying to validate a text box I only want numbers and the letters a – f. I can’t have any other characters. I tried a sub with some if then statements, also I tried the key press event, but the invalid character still gets passed to the variable. How do I validate this text box?

    Thanks
    Bryan

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii >= 48 And KeyAscii <= 57 Then    'this means it's a number
    ElseIf KeyAscii >= 65 And KeyAscii <= 70 Then
        'this means it's a capital letter
    ElseIf KeyAscii >= 97 And KeyAscii <= 102 Then
        'this means it's a lower case letter
    Else
        KeyAscii = 0    'it won't write anything to the text box.
        'this means it's a different character
    End If
    End Sub
    That should work just fine.

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