Handheld Scan Application in VB.NET quiestion.
I made a small application in VB.NET that allows user to scan a bunch of barcodes and save them in the database.
Application works both for the regular computer browser and handheld pocket PC.
Barcode can be either scanned into upc text field and automatically submitted to db or numbers can be manually added into upc text field and pressing Enter will add it to db.
There are also two buttons on the page. One button "Clear" is to clear upc field in case user started a manual input and didn't like it. Second button "Exit" logs out a user.
There is a problem that I don't know how to resolve.
User should just scan a barcode and it will be automatically added to db without pressing any Submit button so user can go through a lot of barcodes fast. In order to achieve this, upc text field has AutoPostBack property set to True.
Then in the Page_Load event if len(upc.text)>0, then data from upc.text gets submitted to db and upc.text gets empty again. If len(upc.text)=0, nothing happens.
So it works fine in case of a handheld. It scans and sets upc.text to empty string. So if I scan and press Exit button after that, I just exit without a problem.
But there is a bug if I input a upc number manually and then press an Exit button for some reason. Pressing a button causes the page to reload and number gets submitted to the database anyway though I just wanted to exit. In fact, if there is any data in the upc field, any action, pressing Enter, pressing the button, clicking with mouse on the screen, causes that data to be submitted to db in the page_load event.
How can I avoid this situation if I still want items to be submitted automatically without pressing any button while scanning?
Re: Handheld Scan Application in VB.NET quiestion.
I normally tie the submit to the enter key. Most scanners can be configured to send a CR after the barcode. I normally key on this that way if the barcode is scanned my code will submit to the server when it sees the CR. If the user types a value my code will submit to the server if and only if they hit the enter key.
Re: Handheld Scan Application in VB.NET quiestion.
"my code will submit to the server when it sees the CR. If the user types a value my code will submit to the server if and only if they hit the enter key. "
This is what I have too. But I have autoPostBack field set to True.
Does your text field has autoPostback set to False?
How do you submit when your code sees CR? I do it in the page_load and it gives me problem.
How I can determine if CR or Enter was pressed? Can you give me an example?
Re: Handheld Scan Application in VB.NET quiestion.
Actually I am not using web pages, everything is coded. I use the form Key Preview and Form Key Press to determine when to call my submit routine.
I would imagion you could do something like this with a web based app as well.
Sounds like the autopostback is a problem. Why not write code to control it?
Re: Handheld Scan Application in VB.NET quiestion.
"form Key Preview and Form Key Press"
what is the code behind those forms?
Re: Handheld Scan Application in VB.NET quiestion.
It is pretty simple.
Keypreview is a property of the form object. If it is set to true then any key pressed causes the form_keypress event to fire giving you the option of intercepting the keystroke there or passing it on to the intended control.
in the keypress event I would check to see if the key pressed was the enter key and if so then I would check to see what had focus at the time it was pressed. Something like.
Code:
Private Sub frmMain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = vbCr Then
Select Case True
Case txtItemID.Focused
If VerifyItem(txtItemID.Text) Then
SubmitItem(txtItemID.Text)
End IF
e.Handled = True
End Select
End If
End Sub
Notice I set e.handled=true in the case where the enter key was pressed and the itemid field has focus. This prevents the enter key from being passed to the textbox.
In the case of input from a scanner that is coming in as serial data or from a scan event I would simply call the same submit sub routine from there.
Re: Handheld Scan Application in VB.NET quiestion.
Thanks,
doesn't work for me. System.Windows.Forms and KeyPress doesn't work for the VB.NET web application. I need to convert it somehow
Re: Handheld Scan Application in VB.NET quiestion.
It's been a while since I have worked with VBScript or JavaScript but I am pretty sure that you should be able to capture a keypress in a given text field from there it is just a matter of writing the code to submit the data.
Re: Handheld Scan Application in VB.NET quiestion.
OK, I resolved the problem. I feel like I owe to the community, maybe it will be useful for somebody who develops a web application for handheld scanner...
upc text field: autoPostBack is set to True.
JavaScript sets focus on upc field when page gets loaded so handheld is ready to scan:
<body onload="javascript:document.form1.upc.focus();">
Two buttons Clear and Exit allow to clear upc field or log out.
Scanned upc is submitted in the page load event automatically when barcode is scanned:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim clear As String = Request.Form("ClearButton")
Dim close As String = Request.Form("ExitButton")
If clear = "Clear" Then
upc.Text = ""
ElseIf close = "Exit" Then
Response.Redirect("Default.aspx")
ElseIf Len(upc.Text) = 0 Then
warning.Text = "Enter UPC"
Else
SubmitItem()
End If
End Sub
Re: Handheld Scan Application in VB.NET quiestion.
Pull down Thread Tools from the top, and MARK AS RESOLVED!