Click here to Skip to main content
15,922,533 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reference Question Pin
SRogers8816-Oct-08 12:14
SRogers8816-Oct-08 12:14 
GeneralRe: Reference Question Pin
Dave Kreskowiak16-Oct-08 13:57
mveDave Kreskowiak16-Oct-08 13:57 
Questionsafe management of unmanaged resources in C# Pin
arcabid16-Oct-08 7:43
arcabid16-Oct-08 7:43 
AnswerRe: safe management of unmanaged resources in C# Pin
Dave Kreskowiak16-Oct-08 10:09
mveDave Kreskowiak16-Oct-08 10:09 
QuestionSerialPort auto find? Pin
Dirso16-Oct-08 6:30
Dirso16-Oct-08 6:30 
AnswerRe: SerialPort auto find? Pin
Dan Neely16-Oct-08 6:44
Dan Neely16-Oct-08 6:44 
Question[Message Deleted] Pin
Hesham Yassin16-Oct-08 6:16
Hesham Yassin16-Oct-08 6:16 
AnswerRe: how to get a variable content from html body using C#? Pin
Vimalsoft(Pty) Ltd16-Oct-08 6:58
professionalVimalsoft(Pty) Ltd16-Oct-08 6:58 
AnswerRe: how to get a variable content from html body using C#? Pin
Paul Conrad16-Oct-08 7:44
professionalPaul Conrad16-Oct-08 7:44 
GeneralMessage Closed Pin
16-Oct-08 7:48
Hesham Yassin16-Oct-08 7:48 
GeneralRe: how to get a variable content from html body using C#? Pin
Paul Conrad16-Oct-08 7:49
professionalPaul Conrad16-Oct-08 7:49 
QuestionUpdating StatusStrip text from class Pin
Brad Wick16-Oct-08 5:47
Brad Wick16-Oct-08 5:47 
AnswerRe: Updating StatusStrip text from class Pin
Simon P Stevens16-Oct-08 6:02
Simon P Stevens16-Oct-08 6:02 
GeneralRe: Updating StatusStrip text from class Pin
Brad Wick16-Oct-08 6:36
Brad Wick16-Oct-08 6:36 
AnswerRe: Updating StatusStrip text from class Pin
Dirso16-Oct-08 6:55
Dirso16-Oct-08 6:55 
GeneralRe: Updating StatusStrip text from class Pin
DaveyM6916-Oct-08 7:07
professionalDaveyM6916-Oct-08 7:07 
AnswerRe: Updating StatusStrip text from class [modified] Pin
DaveyM6916-Oct-08 7:01
professionalDaveyM6916-Oct-08 7:01 
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.

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.