CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    26

    Problem with Enter Key

    I have a Login form which has 2 text boxes to accept user name and password and 2 command buttons Ok and Cancel. I made the OK button as default by setting its property. I am passing the user name and password to a COM DLL to verification.

    The problem now is if I enter correct user name and password and click on OK button it is working fine. If I enter correct user name and password, and if I press Enter Key in password field I am getting an "Invalid Password" Error which I raised in C++.

    I displayed length of the password also before sending for verification. It is displaying correctly. I think the enter key is becoming part of the password.

    How to solve this problem.


    early reply is appreciated
    Chakradhar


    Software Engineer
    IT Solutions India
    Banagalore

  2. #2
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    58

    Re: Problem with Enter Key

    Hi,

    The support by VB for the enter key is limited because this key and the tab key) has a special meaning to Windows.
    For yr password: the textbox.maxlength can be set to the required length of the password.
    Then:
    Sub text1_change()
    If Len(text1.text) = Text1.MaxLength Then
    SendKeys "{Tab}"
    End If
    End Sub
    The code will then send a tab command. If you set the Taborder of the OK command to +1 compared to that of the txtPassword box, then the OK command will be automatically addressed.

    I hope I'm right. Try something like this

    Jan








  3. #3
    Join Date
    May 1999
    Posts
    26

    Re: Problem with Enter Key

    User can enter max. of 10 letters in Password field. But happens if he/she enters less than 10 characters and press enter key.

    chakradhar

    Software Engineer
    IT Solutions India
    Banagalore

  4. #4
    Join Date
    Jul 1999
    Posts
    104

    Re: Problem with Enter Key

    can you give some more information on how your passing the user name and password?
    I think that the problem occurs in that part, because if you look in debug mode to the fields, the string you put in is correct (without any extra characters)


  5. #5
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    58

    Re: Problem with Enter Key

    Try catch the enter key by trapping keyboard activity:
    private Sub Text1.KeyPress(KeayAscii as Integer)
    Select Case KeyASCii
    Case is 13 'I suppose 13 is the enter key
    KeyAscii = 0 'zero
    Case Else
    'no code
    End Select

    Remark: check in an ANSI code list.

    Further: The keypress event can trap the enter key in the textbox only if there's no command button control on the form whose default property is set to true. If the form has a default push button, the effect of processing the enter key is clicking on that button. So set the default property to false.
    Similarly no Escape key goes through this event if there's a Cancel button on the form.

    Jan


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