Click here to Skip to main content
15,896,432 members
Home / Discussions / C#
   

C#

 
QuestionDistinguish between Keyboard and basic Barcode Scanner Pin
J-Cod3r16-Oct-08 4:50
J-Cod3r16-Oct-08 4:50 
AnswerRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Simon P Stevens16-Oct-08 5:17
Simon P Stevens16-Oct-08 5:17 
AnswerRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Brad Wick16-Oct-08 6:21
Brad Wick16-Oct-08 6:21 
GeneralRe: Distinguish between Keyboard and basic Barcode Scanner Pin
J-Cod3r16-Oct-08 20:24
J-Cod3r16-Oct-08 20:24 
GeneralRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Brad Wick17-Oct-08 4:12
Brad Wick17-Oct-08 4:12 
AnswerRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Dirso16-Oct-08 6:58
Dirso16-Oct-08 6:58 
AnswerRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Dave Kreskowiak16-Oct-08 7:09
mveDave Kreskowiak16-Oct-08 7:09 
GeneralRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Brad Wick17-Oct-08 12:49
Brad Wick17-Oct-08 12:49 
I am trying to figure out the best way to integrate this so that it can be customizable. My barcodes are always 12 characters long but you never know what might change in the future. So my thought is to look for two @@ which means were starting the barcode and then two @@ means the barcode has ended. I have activated the forms keypreview so I can now watch the keys on KeyPress. The problem I am having is trying to figure out the best way to make this dynamic and customizable by a config file incase the user wants to use three #'s instead of @.

// First we set the config variables as to what the barcode variables will be
private static string ConfigBarcodePreSuffix = "@";
private static int ConfigBarcodePreSuffixTimes = 2;

// Set the form variables so we can capture whats going on
private static string Scanned_BarcodeText = ""; // Will hold the final barcode value
private static bool Scanned_BarcodeBeingScanned = false; // Will hold a bool value so we know we scanning the barcode
private static int Scanned_PreSuffixFoundTimes = 0; // How many times have we found this presuffix

private void frmEventTicketVerify_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar.Equals(ConfigBarcodePreSuffix))
    {
        // This is the character were looking for so lets find out if its the start or end
        if (!Scanned_BarcodeBeingScanned)
        {
            // We have not started scanning the barcode so lets see if we hit it
            if (Scanned_PreSuffixFoundTimes == ConfigBarcodePreSuffixTimes)
            {
                // This is how many times they are looking for the prefix so lets start the barcode
                Scanned_BarcodeBeingScanned = true;
            }
        }
        else
        {
            // This is the ending of the barcode
            if (Scanned_PreSuffixFoundTimes == ConfigBarcodePreSuffixTimes)
            {
                // This is how many times they are looking for the prefix so lets start the barcode
                Scanned_BarcodeBeingScanned = false;
            }
        }
        // Move the prefix count up
        Scanned_PreSuffixFoundTimes++;
    }
    else
    {
        // This wasnt the key we were looking for so lets reset it
        Scanned_PreSuffixFoundTimes = 0;
    }

    if (Scanned_BarcodeBeingScanned)
    {
        // We are still inserting text from the barcode, so lets continue to add it
        Scanned_BarcodeText += e.KeyChar.ToString();
    }
    else if (!Scanned_BarcodeText.Trim().Equals(""))
    {
        // Here is the final barcode
        MessageBox.Show(Scanned_BarcodeText);
    }           
}


I am just starting to test this code, and I am not the best at C# so if you see any improvements or bugs I would be greatful.
GeneralRe: Distinguish between Keyboard and basic Barcode Scanner Pin
Dave Kreskowiak17-Oct-08 16:35
mveDave Kreskowiak17-Oct-08 16:35 
QuestionSpeed Up Try Catch Pin
fly90416-Oct-08 4:36
fly90416-Oct-08 4:36 
AnswerRe: Speed Up Try Catch Pin
SeMartens16-Oct-08 4:49
SeMartens16-Oct-08 4:49 
AnswerRe: Speed Up Try Catch Pin
Paul Conrad16-Oct-08 9:24
professionalPaul Conrad16-Oct-08 9:24 
QuestionMSI Setup - custom action rollback Pin
Mogyi16-Oct-08 3:24
Mogyi16-Oct-08 3:24 
AnswerRe: MSI Setup - custom action rollback Pin
HemJoshi16-Oct-08 3:47
HemJoshi16-Oct-08 3:47 
GeneralRe: MSI Setup - custom action rollback Pin
Mogyi16-Oct-08 4:10
Mogyi16-Oct-08 4:10 
QuestionWhat is best way? Pin
Majid_grok16-Oct-08 2:45
Majid_grok16-Oct-08 2:45 
RantRe: What is best way? Pin
Nagy Vilmos16-Oct-08 3:06
professionalNagy Vilmos16-Oct-08 3:06 
Questiongot problem with sequence of event execution Pin
Krazy Programmer16-Oct-08 2:37
Krazy Programmer16-Oct-08 2:37 
AnswerRe: got problem with sequence of event execution Pin
Guffa16-Oct-08 3:17
Guffa16-Oct-08 3:17 
GeneralRe: got problem with sequence of event execution Pin
Krazy Programmer16-Oct-08 19:44
Krazy Programmer16-Oct-08 19:44 
GeneralRe: got problem with sequence of event execution Pin
Guffa17-Oct-08 13:38
Guffa17-Oct-08 13:38 
GeneralRe: got problem with sequence of event execution Pin
nelsonpaixao16-Oct-08 12:36
nelsonpaixao16-Oct-08 12:36 
GeneralRe: got problem with sequence of event execution Pin
Krazy Programmer16-Oct-08 19:44
Krazy Programmer16-Oct-08 19:44 
QuestionThreads and WinForms Pin
Programm3r16-Oct-08 1:45
Programm3r16-Oct-08 1:45 
AnswerRe: Threads and WinForms Pin
Alan N16-Oct-08 1:59
Alan N16-Oct-08 1:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.