Results 1 to 17 of 17

Thread: [RESOLVED] Code to Display Data Matrix Barcode Reading With Separators

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Resolved [RESOLVED] Code to Display Data Matrix Barcode Reading With Separators

    Hi, hope you are all well

    I have a form which has 4 textboxes, txt_reading, txt_part, txt_ponum and po_batch.
    Txt_reading is the on_focus textbox and when I scan a data matrix barcode it displays a long string within the textbox, however it does not include the separator (space) between the 3 other fields and therefore there is no way for me to split the text up and push the values into the required textboxes.

    The barcode is made up using:
    [)>«RS»06«GS»Ppart_number«GS»Kpo_numb«GS»Ubatch_no

    An example reading I get now is 06PF00012K505123UABC123
    I want 06 PF00012 K505123 UABC123.

    Anyone created something like this before? Thanks in advance

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,823

    Re: Code to Display Data Matrix Barcode Reading With Separators

    try and use Substring
    is the lenght allways the same ?

    Code:
     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim s As String = "06PF00012K505123UABC123"
    
            MessageBox.Show(s.Substring(0, 2))
            MessageBox.Show(s.Substring(2, 7))
            MessageBox.Show(s.Substring(s.Length - 7))
        End Sub
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Hi Chris, Thanks for replying.
    That is part of the problem, as the fields I want to split up are not always the same length, I have to make use of the group separator (the space) in order to be sure I have got the right number of characters every time. However, when I am scanning the barcode, the resulting string does not contain the space and therefore I cannot split. I am thinking visual studio needs to be made aware to expect a separator, have searched online but to no avail

  4. #4
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    682

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Try this:

    Code:
    txt_reading.Text = txt_reading.Text.Replace(Chr(29), " ")

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Hi Paul

    Thanks for taking time out and trying to help. Unfortunately I did not get the required result by placing the above code within a button or at textchange event

    Thanks Once Again

  6. #6
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    682

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Oh well, worth a try. I have no knowledge of barcode readers but Google suggested that the separator character might be ASCII code 29. I wasn't sure if putting the string into a textbox would strip out non-printing characters but a quick test with a string that contained ASCII 29 suggested that was not the case. Perhaps some other ASCII code below 32 might be used?

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,489

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Not real versed in bar codes other than scanning them at the grocer's... but... a few things come to mind:

    Are you *sure* the group separator is a space?

    What created the bar codes in the first place? How was the <<GS>> configured? Does it actually result in a space being part of the bar code? Or some other signal that it would interpret back in as a space?

    Have you tried reading through the characters one by one and examining the ASCII values, looking for a non-printable character that maybe you need to convert into a space?

    Barcode scanners are often keyboard analogs, so it wouldn't surprise me to also find out that the bar code itself may be the culprit.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Hi all

    Just an update - still not cracked it

    The barcode is generated within the bartender software and when I scan this barcode directly into the visual studio textbox, I get a long line of text with no separators.
    I change the settings on the scanner so to +alternate keys and scanned into notepad++ and got the group separators but nothing directly into the textbox..
    However when I copy the text in notepad ++ into the textbox, I am getting a space where the group separators are... really confused.

    It seems like the scanner is sending the correct string, but visual studio is not recognising the group separators and just ignoring them...

  9. #9
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    682

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Have you looked through the string for non-printable ASCII values? Add a Listbox to your form and then try something like this:

    Code:
    For Each s As String In TextBox1.Text
        ListBox1.Items.Add(Asc(s))
    Next
    Look for any value below 32 or above 127. That could be your separator.

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Thank you for taking the time out to reply, will try this at work tomorrow and let you know what happens.. apologies, I am a beginner so didn't know how to check the non-printable ascii values.. glad you inserted some code in there too ha!

    Have a good night

  11. #11
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    682

    Re: Code to Display Data Matrix Barcode Reading With Separators

    If you do it like this you will see your barcode characters printed vertically so you should be able to spot the separator:

    Code:
    For Each s As String In TextBox1.Text
        ListBox1.Items.Add(s & ":" & Asc(s))
    Next

  12. #12

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Hi, I have the following to report:
    Scanned barcode into textbox and got the following string in textbox:

    [)>06PF02277-03Q192.000K510398241T519046713S51904671201013110551AN123VKCMT

    Listbox looks something like this (part typed here and populated upon button press. , Indicates new line)

    [:91, ):41, >:62, :30, 0:48, 6:54, p:80, f:70, 0:48, 2:50, 2:50, 7:55, 7:55, -:45, 0:48, 3:51, Q:81, 1:49, 9:57, 2:50, .:46 0:48, 0:48, 0:48, K:75

    Scanning barcode directly into notepdd ++ gives this

    [)>RS06GSPF02277-03GSQ192.000GSK51039824GS1T51904671GS3S51904671201013110551GSAN123VKCMTGSRSEOT
    where gs rs are separators

    copying from notepad to the textbox again gives me my original visual studio value! Hope this helps and I pray this allows you to give me a solution Thank you for your time so far

  13. #13
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    682

    Re: Code to Display Data Matrix Barcode Reading With Separators

    I think my original suggestion was close. Try this:

    Code:
    txt_reading.Text = txt_reading.Text.Replace(Chr(29), " ")
    txt_reading.Text = txt_reading.Text.Replace(Chr(30), " ")

  14. #14

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Mate your a genius... I will love you forever ha!

    So it seems like the barcode had lots of group separators instead of record separators and where the only record separator existed, the program replaced it with a space as per your code. So in between the new records I changed the GS to an RS and voila!! there is a space where I want there to be!!

    My final question (sorry!!) I added this to the "on change" code within the text box but the resulting text is backwards! How do I now get the above to happen automatically without the need of a button press.
    FYI the users will press confirm so the group separators are irrelevant as they wont be scanning scanning quickly !

    Thank you mate

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,729

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Reversing the order is a common problem when altering text in a Change event, because it isn't just the text that is being altered - there is also the Selection (the cursor position plus any highlighted text next to it) which gets reset.

    https://docs.microsoft.com/en-us/dot...orkdesktop-4.8

    You can fix the reversing by reading the value of SelectionStart and SelectionLength before altering text, and setting them back to those values after altering the text.

  16. #16

    Thread Starter
    Member
    Join Date
    Oct 2020
    Location
    UNITED KINGDOM
    Posts
    59

    Re: Code to Display Data Matrix Barcode Reading With Separators

    Hi Guys

    I have now got the working model and thank you all to those who commented and big thanks for paul whose advice without I would never have resolved this, I am a new user so will see how I can mark you up or whatever it is referred to here. Thanks once again.

    Might be a long winded way, but I read the barcode into one textbox then altered this into another and then split out the text.

    Code:
            txtresult.Text = txt_barcode.Text.Replace(Chr(30), " ")
    
            Dim source As String = txtresult.Text
            Dim extract As String = ""
            Dim start As Integer = source.IndexOf(" P") + 2
            Dim [end] As Integer = source.IndexOf(" Q")
            If start >= 0 AndAlso [end] > start Then
                extract = source.Substring(start, [end] - start)
            End If
            txt_comp.Text = extract
    
            Dim source1 As String = txtresult.Text
            Dim extract1 As String = ""
            Dim start1 As Integer = source1.IndexOf(" K") + 2
            Dim [end1] As Integer = source1.IndexOf(" 1")
            If start1 >= 0 AndAlso [end1] > start1 Then
                extract1 = source.Substring(start1, [end1] - start1)
            End If
            txt_po.Text = extract1
    
            Dim source2 As String = txtresult.Text
            Dim extract2 As String = ""
            Dim start2 As Integer = source2.IndexOf(" 3") + 3
            Dim [end2] As Integer = source2.IndexOf(" A")
            If start2 >= 0 AndAlso end2 > start2 Then
                extract2 = source.Substring(start2, end2 - start2)
            End If
            txt_batch.Text = extract2
    Thanks once again

  17. #17
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    682

    Re: [RESOLVED] Code to Display Data Matrix Barcode Reading With Separators

    Glad to be of help. There are loads of ways of manipulating strings and it might be possible to make your code a bit more efficient, but with short strings you are not going to suffer from poor performance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width