Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a windows form application, on form load my focus is on the text box where i have to get the input from barcode reader, my application is working fine but there is a problem that after getting input my application show the data against the id, but when i get another input from barcode reader it does not remove the previous value in text box and mix both value, i can not call the textbox.clear function after fetching data because i need the data in textbox till next recorde enter.
Posted
Comments
joginder-banger 12-Dec-13 14:04pm    
You can clear the textBox before the fetching data.

You either need to remove it when you have used it, or talk to the barcode scanner manufacturer - most scanners can be configured to provide a special start and / or end code so you can spot when a new code is arriving, or when the old one is complete. Exactly how you configure it differs from manufacturer to manufacturer (and sometimes model to model!)
 
Share this answer
 
you can try this code.
C#
TextBox tx = new TextBox();
            tx.Text = "";
            tx.Text = string.Empty;
            tx.Clear();

if query hit the reply.
 
Share this answer
 
Comments
entiresol 12-Dec-13 14:05pm    
But i don't want to clear my text box untill i get new input.
joginder-banger 12-Dec-13 14:14pm    
some share your code for better understanding your problem and also define where you want to a condition??
In addition to the common-sense suggestions you got from OriginalGriff, I'd like to suggest you immediately copy the incoming result of a scan into either a private memory field of an appropriate Type, or to another on-screen TextBox.

Whether you might need to store/save several, rather than one, scan result would depend on the nature of your scanning process: if the scans are being done automatically, not under the control of a human operator ... as may happen in an assembly line ... well: that's a whole different scenario.

You could also save a history of the scans along with a DateTime if needed, using an instance of a Struct, or Class, to represent a single scan.

If you give more details of the nature of the scanning process, and the role (if any) of the human operator, you can get more focused advice.
 
Share this answer
 
Barcode reader can be configured to automatically send a [Enter] after it reads a barcode.

With the [Enter] key stroke detected in textBox1, cache the code in a private string value within the class.

Whenever any method wants to access the barcode value, get it from the private string.

Example:

C#
public partial class Form2 : Form
{
    string lastScannedCode = "";

    public Form2()
    {
        InitializeComponent();
    }

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.Enter)
        {
            lastScannedCode = textBox1.Text;
            label1.Text = lastScannedCode;
            textBox1.Clear();
        }
    }

    void ShowTheLastScannedCode()
    {
        MessageBox.Show(lastScannedCode);
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900