Solved

Question about Text Field in VB6

Posted on 2010-09-24
8
296 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

18 Experts available now in Live!

Get 1:1 Help Now