Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Question about Text Field in VB6

Posted on 2010-09-24
8
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Suggested Courses

636 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