Click here to Skip to main content
15,889,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I can get the QR code data in my text boxes but i just want to get the last ten charcters of the QR code data.

What I have tried:

I tried windows form application using threading, in three text boxes and a label i can read the QR codes but for the end user when place the cursor he should see only last 10 charcters from the QR code.

Please help me
[EDIT - OP code from comment]
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Barcodetesting_14_7
{
	public partial class Form1 : Form
	{

		private Dictionary<textbox, textbox=""> TextBoxOrder = new Dictionary<textbox, textbox="">();
		private void Form1_Load(object sender, EventArgs e)
		{

		}

		public Form1()
		{
			InitializeComponent();

			TextBoxOrder.Add(BarcodeInput1, BarcodeInput2);
			TextBoxOrder.Add(BarcodeInput2, BarcodeInput3);
			TextBoxOrder.Add(BarcodeInput3, BarcodeInput1);

			BarcodeInput1.Tag = 1;
			BarcodeInput2.Tag = 2;
			BarcodeInput3.Tag = 3;

			BarcodeInput1.KeyDown += BarcodeInputKeyDown;
			BarcodeInput2.KeyDown += BarcodeInputKeyDown;
			BarcodeInput3.KeyDown += BarcodeInputKeyDown;

			BarcodeInput1.Leave += BarcodeInputLeave;
			BarcodeInput2.Leave += BarcodeInputLeave;
			BarcodeInput3.Leave += BarcodeInputLeave;
		}

		private void BarcodeInputKeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter && ActiveControl.GetType() == typeof(TextBox))
			{
				TextBox nextTextBox;
				if (TextBoxOrder.TryGetValue((TextBox)ActiveControl, out nextTextBox))
				{
					e.Handled = true;
					e.SuppressKeyPress = true;
					nextTextBox.Focus();
				}
			}
		}

		private void BarcodeInputLeave(object sender, EventArgs e)
		{
			if (sender.GetType() == typeof(TextBox))
			{
				TextBox textBox = (TextBox)sender;
				if (textBox.Tag.GetType() == typeof(int))
				{
					BarcodeScanned(textBox.Text, (int)textBox.Tag);
				}
			}
		}

		private void BarcodeScanned(string barcode, int order)
		{
			DemoLabel.Text = order.ToString() + ": " + barcode;
		}
	}
}
Posted
Updated 3-Jul-19 1:37am
v2
Comments
F-ES Sitecore 3-Jul-19 5:22am    
That would involve modifying your code, which we can't see.
Member 14519564 3-Jul-19 5:26am    
Here the code, please modify it to read only last ten charcters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Barcodetesting_14_7
{
public partial class Form1 : Form
{

private Dictionary<textbox, textbox=""> TextBoxOrder = new Dictionary<textbox, textbox="">();
private void Form1_Load(object sender, EventArgs e)
{

}

public Form1()
{
InitializeComponent();

TextBoxOrder.Add(BarcodeInput1, BarcodeInput2);
TextBoxOrder.Add(BarcodeInput2, BarcodeInput3);
TextBoxOrder.Add(BarcodeInput3, BarcodeInput1);

BarcodeInput1.Tag = 1;
BarcodeInput2.Tag = 2;
BarcodeInput3.Tag = 3;

BarcodeInput1.KeyDown += BarcodeInputKeyDown;
BarcodeInput2.KeyDown += BarcodeInputKeyDown;
BarcodeInput3.KeyDown += BarcodeInputKeyDown;

BarcodeInput1.Leave += BarcodeInputLeave;
BarcodeInput2.Leave += BarcodeInputLeave;
BarcodeInput3.Leave += BarcodeInputLeave;
}

private void BarcodeInputKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && ActiveControl.GetType() == typeof(TextBox))
{
TextBox nextTextBox;
if (TextBoxOrder.TryGetValue((TextBox)ActiveControl, out nextTextBox))
{
e.Handled = true;
e.SuppressKeyPress = true;
nextTextBox.Focus();
}
}
}

private void BarcodeInputLeave(object sender, EventArgs e)
{
if (sender.GetType() == typeof(TextBox))
{
TextBox textBox = (TextBox)sender;
if (textBox.Tag.GetType() == typeof(int))
{
BarcodeScanned(textBox.Text, (int)textBox.Tag);
}
}
}

private void BarcodeScanned(string barcode, int order)
{
DemoLabel.Text = order.ToString() + ": " + barcode;
}
}
}
CHill60 3-Jul-19 5:30am    
Nobody is going to attempt to read an unformatted code dump - I've updated your question with your code - next time use the "Improve Question" link to update your post
Member 14519564 3-Jul-19 5:51am    
ok, thanks

Full answer as OP is struggling
C#
DemoLabel.Text = order.ToString() + ": " + ((barcode.Length > 10) ? barcode.Substring(barcode.Length - 10, 10)  : barcode);
 
Share this answer
 
v2
Comments
Member 14519564 3-Jul-19 7:52am    
at line Application.Run(new Form1()); it is showing Exception unhandled System.ArgumentOutOfRangeExceptions: startindex cannot be less than zero
Dave Kreskowiak 3-Jul-19 8:34am    
That means your barcode string is 9 characters or shorter.

DEBUGGER! Learn to use it or struggle to write code for the rest of your coding life.
Richard MacCutchan 3-Jul-19 10:41am    
Maybe you should spend some time learning more about .NET and Windows Forms, your questions are not at all specific to reading barcodes.
Member 14519564 3-Jul-19 12:43pm    
Ok, Thanks
Dave Kreskowiak 3-Jul-19 11:54am    
How on earth do you expect to get a description of how to write an entire application in a couple of forum posts?
Once you have decoded the barcode into a text string you can use Length and SubString of String Class (System) | Microsoft Docs[^] to get the last 10 characters.
 
Share this answer
 
Comments
Member 14519564 3-Jul-19 5:54am    
can you please modify the above code to get last 10 charcters.
CHill60 3-Jul-19 6:52am    
You can do threading and read barcodes but can't use a simple method or property?
Change
DemoLabel.Text = order.ToString() + ": " + barcode;
to
DemoLabel.Text = order.ToString() + ": " + barcode.Substring(barcode.Length - 10, 10);
Member 14519564 3-Jul-19 7:10am    
Thanku so much. Its working..:)
Member 14519564 3-Jul-19 7:23am    
Its working but sometimes its showing: Unhandled exception has occured in your application. StartIndex cannot be less than zero.

What i have to do, to rectify this error?
CHill60 3-Jul-19 7:31am    
Check to see if the barcode.Length is greater than 10 first - if not then just display the entire barcode

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