Solved

Question about Text Field in VB6

Posted on 2010-09-24
8
299 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user 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…

791 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