Solved

Question about Text Field in VB6

Posted on 2010-09-24
8
297 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:JRHIT
  • 3
  • 2
  • 2
8 Comments
 
LVL 16

Expert Comment

by:carsRST
ID: 33753853
Use the TextBox1_Change() event.  This will fire when any data is in your text field.
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33753856
Follow up...

TextBox1 - would be what ever you name your field.
0
 
LVL 11

Expert Comment

by:kbirecki
ID: 33753930
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:Brook Braswell
ID: 33754202
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
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33754223
I'm unclear on why checking for 4 characters is important?
0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 33754581
I believe there are assumptions based on the clients request.
I do not believe that the 4 chars are important to force a check especially since the textbox already will prevent more chars.
The biggest reason then would be that a user can manually type in the text box and the client has requested the cmdLogin click event to be called when the 4 chars are reached.
Again:  That would be a good reason to check for a key press from the scanner.

Alternatively you could ignore the hard coding of 4 chars and set the check for the text boxes max length...

TextBox1_Change()
   If Len(Trim(TextBox1.Text)) >= TextBox1.MaxLength Then
     TextBox1.Text = trim(TextBox1.Text)
      cmdLogIn_Click
   end if
End Sub


0
 
LVL 11

Expert Comment

by:kbirecki
ID: 33754714
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 56
move one pixel 4 58
Windows Service to Receive TCP Packets 4 117
Basic Java Case or If-Else statement... 3 43
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now