Click to See Complete Forum and Search --> : Problem with Enter Key


Chakradhar
July 20th, 1999, 12:49 AM
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

Jan Businger
July 20th, 1999, 03:32 AM
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

Chakradhar
July 20th, 1999, 03:53 AM
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

freek
July 20th, 1999, 04:36 AM
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)

Jan Businger
July 20th, 1999, 05:27 AM
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