Solved

Question about Text Field in VB6

Posted on 2010-09-24
8
300 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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