Solved

Scanned Barcode to Visual Basic Textboxes - Change Textbox Focus with Javascript

Posted on 2014-03-18
9
1,105 Views
Last Modified: 2016-10-28
Hi all!

We have a .NET application to register items in a large archive. The location in the archive is a combination of room, section, and shelf. Presently the item number and location is entered manually in the archive system but we want to switch to barcodes - a location will have a barcode and an item in the archive will have as barcode.

On a webform we have two textboxes and a button and want to perform this:

1/ Focus is set on the first textbox.
2/ The items barcode is scanned and the scanned value goes in the first textbox.
3/ At the same time as 2/ happens Javascript must move focus to the second textbox.
4/ The location barcode is scanned and the scanned value goes in the second textbox.
5/ At the same time as 4/ happens Javascript must move focus to the textbox in order for nthe user to press enter and have the form processed. Instead of the user press enter, is it possible to have Javascript 'click the button'?

I have tried this:

TextBox1.Attributes.Add("onkeydown", "document.getElementById('" & TextBox1.ClientID & "').value=''; document.getElementById('" & TextBox2.ClientID & "').focus();")

but when I scan in TextBox1, focus is moved to TextBox2 and the scanned value is transferred to TextBox2 but should be transferred to TextBox1 before focus is changed.

Any suggestions?
0
Comment
Question by:Kim Neesgaard
  • 5
  • 2
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39940091
Try using "onchange" event instead of "onkeypress". If you get the same behaviour, you may have to add a condition like number of characters in the textbox to change the focus because the focus is changing as soon as first character enters the textbox.
0
 

Author Comment

by:Kim Neesgaard
ID: 39941669
-> CodeCruiser
In this case I cannot use number of characters as it is a location with different number of characters.

If I use:

TextBox1.Attributes.Add("onchange", "document.getElementById('" & TextBox2.ClientID & "').focus();")

the scanned value is entered in TextBox1 but focus is not set on TextBox2?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 300 total points
ID: 39948891
Does your scanner provide any settings? Such as sending a Tab key at the end of the scan?
0
 

Author Comment

by:Kim Neesgaard
ID: 39952887
I have now adjusted the scanner to add a at the end of the scan and will try to detect it.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Kim Neesgaard
ID: 39952890
...to add a tab at the end...
0
 

Author Comment

by:Kim Neesgaard
ID: 39955703
-> CodeCruiser
Tab was the right cue!!

I contacted my scanner provider and learned how to add a tab-character AFTER the scanned value and this works. When a value is scanned to a textbox, the tab moves the cursor to the next tab order on the form. A simple and good solution!

Thank you very much!!
Barcode-Scanner.png
0
 

Expert Comment

by:RAM PRASAD
ID: 41863707
I have used two textboxes as text1 and text2 and one comm1 conttrol .. now we use these  code . after running the program auto cursor will show in text1. now i go to scan then scaned value all inputed in the text1. and cursor auto move to text2 but next scanning not show..???? now i will want to scan second barcode in  text2 for matching two barcode are related one system or not...
i used coding in mscomm-oncomm()

' for connection making on form load()
MSComm1.CommPort=1
MSComm1.CommPort=3
MSComm1.Setting="9600,n,8,1"
MSComm1.InputLen=0
MSComm1.InbufferSize=100
MSComm1.Rthershold=0
MSComm1.PortOpen=true
MSComm1.Output="ok"
MSComm1.OutBufferCount
........................
Now On MSComm1..()
Dim i As Integer
Dim buffer As String
buffer=""
buffer=MSComm1.Input
for i=1to Len(buffer)
text1.text=text1.text &Chr(Asc(Mid$(buffer,i,17)))
next j
buffer=""
buffer=MSComm1.Input
for j=1to Len(buffer)
text2.text=text2.text &Chr(Asc(Mid$(buffer,j,17)))
next j
.....ok please Solve this ?
0
 

Author Comment

by:Kim Neesgaard
ID: 41863780
Hi RAM PRASAD!

As you can see above, we used the solution to have tab added to the barcode reading.


Best regards
Kim Neesgaard
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

760 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

20 Experts available now in Live!

Get 1:1 Help Now