JRHIT
asked on
Question about Text Field in VB6
I have a text field that I have a maxlength set at 4 characters. I am having cards scanned in with a barcode and the resulting 4 character set is what displays in the text field. I want to emulate the cmdLogin_Click() as soon as the 4 characters are in the text field.
How do I do this?
How do I do this?
Use the TextBox1_Change() event. This will fire when any data is in your text field.
Follow up...
TextBox1 - would be what ever you name your field.
TextBox1 - would be what ever you name your field.
You can use the Change event as carsRST suggests, but you should also check in that event if you have your four characters before doing anything because Change will fire on each character entered into the field, so with four chars being entered, it will fire four times. You probably only want it to do something once four characters are entered. Something like:
TextBox1_Change()
If len(TextBox1.Text)>=4 then
'Do stuff here
'else
'Do Nothing
end if
TextBox1_Change()
If len(TextBox1.Text)>=4 then
'Do stuff here
'else
'Do Nothing
end if
kbirecki is correct that you will want to check the length of your text.
Remember that most scanners put an Enterkey at the end of each scan
In that case you could use the TextBox1_KeyPress event
TextBox1_KeyPress(KeyAscii as integer)
if KeyAscii = 13 then
cmdLogIn_Click
end if
End Sub
TextBox1_Change()
if len(trim(Textbox1.text)) = 4 then
TextBox1.Text = trim(TextBox1.Text)
cmdLogIn_Click
end if
End Sub
Remember that most scanners put an Enterkey at the end of each scan
In that case you could use the TextBox1_KeyPress event
TextBox1_KeyPress(KeyAscii
if KeyAscii = 13 then
cmdLogIn_Click
end if
End Sub
TextBox1_Change()
if len(trim(Textbox1.text)) = 4 then
TextBox1.Text = trim(TextBox1.Text)
cmdLogIn_Click
end if
End Sub
I'm unclear on why checking for 4 characters is important?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What Brook1966 said is right. In other words, if you only put a call to execute cmdlogin_Click in the OnChange event, it would fire immediately after the first character from the scanner is received, and then again after the second character is received, and so on until the scanner stopped sending characters. The OnChange event fires after every character entered into the field. So if you expect 4, then don't do anything until you reach four characters (or the max field length as Brook1966 suggests). Thus the check for 4 chars.