Results 1 to 4 of 4

Thread: Validation

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Jamaica
    Posts
    0

    Red face Validation

    I just look at an example on Master Karl's tutorial and need help. I am trying to passsword protect an application. I want the password to be a number, but I want to have control over what the person types in the password textbox.

    EG.

    ENTER YOUR PASSWORD ******


    If the person types in letters, the computer will try to compare it with the pre - set numbers and return a TYPE MISMATCH error.

    How can I change the VALIDATE event so that the computer will still return a "INCORRECT PASSWORD" as it would have done if the person types in an incorrect #?

    THANKS
    CBJ

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350
    There was an exercise just like this in MS's MCSD material. Don't let it get as far as trying to check it, prevent the user typing a non-numeric in the first place. Assuming it's a text box, in the box's change event, use an if to check if the input's not numeric and so then empty the box.
    .

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350

    Or...

    Alternatively, you could make your pre-set numbers not be numbers, but strings.
    .

  4. #4
    Lively Member
    Join Date
    Jun 2001
    Location
    Banana Republic
    Posts
    115

    Thumbs up Taken from one of my Code collection

    VB Code:
    1. Private Declare Function SetWindowLong Lib "user32" Alias _
    2. "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal _
    3. dwNewLong As Long) As Long
    4.  
    5. Private Declare Function GetWindowLong Lib "user32" Alias _
    6. "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    7.  
    8. Private Const GWL_STYLE = (-16)
    9. Private Const ES_UPPERCASE As Long = &H8&
    10. Private Const ES_LOWERCASE As Long = &H10&
    11. Private Const ES_NUMBER    As Long = &H2000
    12. Dim DefStyle&
    13.  
    14. Private Sub Form_Load()
    15. DefStyle = GetWindowLong(txtEdit.hwnd, GWL_STYLE)
    16. SetTextBoxType txtEdit, ES_NUMBER
    17. End Sub
    18.  
    19. Private Sub SetTextBoxType(Txt As TextBox, tp As Long)
    20. Call SetWindowLong(Txt.hwnd, GWL_STYLE, DefStyle Or tp)
    21. End Sub

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