Results 1 to 26 of 26

Thread: Write Code to Alert Users if Duplicate Barcode has been scanned

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Question Write Code to Alert Users if Duplicate Barcode has been scanned

    Hello, I am using Visual Studio 2015 and need to write code to do the following.

    A user will use a 1D barcode scanner to scan a label.
    The label scanned needs to be saved.
    If the same label is scanned I need a pop up to appear and say something like "Warning this Barcode has already been used Contact IT immediately"



    I don't mind which programming language is used. I am a server\network guy and have been assigned with this task (since our developer was fired) to be put in place by 12:00 (noon) tomorrow. LOL I told him i would try my best!

    I will set up a laptop beside the line with a barcode scanner attached. If any other information is needed feel free to reach out. Thank you very much in advance if you decide to help me!

  2. #2
    Frenzied Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    1,104

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    What part do you need help with? Where are the codes being stored? Is this part of an inventory program?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Honestly I need help on all of it. We currently use BARCOM to store information and run the programs on the thinclients on the floor. I'm guessing ill need to set up a database, then write code in VS to make a program to write and store that information in the DB.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Sorry, the reason for this to be set up is the president of the company want 2 checks to make sure a duplicate barcode doesn't get out the door. One in BARCOM and one completely separate from the current database.

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    I literally just wrote a program for a client that had a box of barcodes that was scanned using Cognex and then any unreadable barcodes were scanned manually by a handheld scanner. There couldn't be any duplicates either, but there was the possibility for a "sample" barcode that was used if the handheld scanner failed.

    In this case, I had a DataGridView that represented each barcode that was scanned (in this case they wanted it to be labeled column A-[x] and row 1-[y]) and color coordinated the DataGridViewCells so that green represented a cell that the barcode was able to be read, red indicated that the cell was unreadable, black indicated that the cell was deliberately left blank, and blue indicated that the cell used the sample barcode. When the user single clicked on the DataGridViewCell and it was a barcode that was already read, it would display the value from the barcode. When the user single clicked on the DataGridViewCell and it didn't have a barcode value then it launched a dialog that prompted for the user to manually scan the barcode using the handheld scanner. When the user double-clicked on the DataGridViewCell it would toggle it to blank or unreadable (depending on its current state). This worked well and was relatively simple. The client wanted the results output as a JSON file, which was done by me overriding the ToString method of the DataGridViewCell.

    I could certainly do this, but I don't know of anyone that would just up and do this for you without being paid. If you needed help on a specific part of the project that's one thing, but to do the entire project for you that is another.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    Frenzied Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    1,104

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    I would take a look at what BARCOM has to offer in the way of scripting or customization first. Or are you thinking of a completely separate system and workstation with its' own bar code scanner? Give me an idea of what you have in mind for the hardware.
    An app would be easy to write. Like you said, make a simple SQL Db table. But also if you get a new bar code scanner you could use their inventory software. I'm guessing it would complain if you tried to make a duplicate entry.

  7. #7
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    one Piece of Information i am missing is: how Long shall scanned Barcodes be stored to verify if the same Comes again? what answer fits best?
    a) only for the lifetime of the process, i.e. user starts app, scans Barcodes any duplicates are reported, user Closes app and restarts, any Barcode scanned in the first run is forgotten and can be rescanned without error
    b) scanned Barcodes Need to be stored for a day or week, any rescan of a Barcode scanned more than a day/week ago is accepted without error
    c) scanned Barcodes Need to be stored forever

    if its b) or c): how many barodes are scanned per day?

    another Thing Comes to mind: do you have only one Workstation where this program is runnning or multiple ones that Need to sync, i.e. Barcode xy is scanned on Workstation 1, then 10 minutes later at Workstation 2->an error shall appear on WS 2.

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    I appreciate all the replies and messages asking for pay but unfortunately the company is not willing to compensate a third party for this (I could repay you if you need help with servers/networking/firewall/and recruiters for a new job). I have a basic understanding of how all this works I just need to be pointed in the right direction. Below is a picture showing what I need.

    Name:  IMG_6038.jpg
Views: 262
Size:  28.1 KB
    Last edited by learningsql; Mar 21st, 2018 at 08:44 AM.

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Quote Originally Posted by digitalShaman View Post
    one Piece of Information i am missing is: how Long shall scanned Barcodes be stored to verify if the same Comes again? what answer fits best?
    a) only for the lifetime of the process, i.e. user starts app, scans Barcodes any duplicates are reported, user Closes app and restarts, any Barcode scanned in the first run is forgotten and can be rescanned without error
    b) scanned Barcodes Need to be stored for a day or week, any rescan of a Barcode scanned more than a day/week ago is accepted without error
    c) scanned Barcodes Need to be stored forever

    if its b) or c): how many barodes are scanned per day?

    another Thing Comes to mind: do you have only one Workstation where this program is runnning or multiple ones that Need to sync, i.e. Barcode xy is scanned on Workstation 1, then 10 minutes later at Workstation 2->an error shall appear on WS 2.

    C. The barcodes will be stored indefinite. I would say a little less than 200 are scanned per day. Yes, there will only be one workstation where this will be set up.

  10. #10
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    What you want if it doesnt exist? Commit the new serial to DB?

  11. #11
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Quote Originally Posted by learningsql View Post
    C. The barcodes will be stored indefinite. I would say a little less than 200 are scanned per day. Yes, there will only be one workstation where this will be set up.
    So you got to use a database of some Kind. if ist just 200 per day, also a Textfile would work for some years, an Access database would be a better Option or a real database like MSSQL would be best.

    You Need to create the database and table, then on a scan do a select * where Barcode=ScannedCode and see if you get a result. if so, Show the warning message, if not then fine, go and insert it to the table.
    i would also add a dtScanned to the table so that you can tell when a new Barcode was scanned.

  12. #12
    Frenzied Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    1,104

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    It's a simple Windows Form app. The Barcode software inputs the text. Your form has a table that's linked to the table on your server using ORM like ADO.NET or Entity Framework. If it doesn't exit, add it and turn the form background green. Then update your table. If it does exist, flash the background red and issue the warning. Optionally add it as well. Wouldn't hurt. I'd make the form full screen with big text. Like a kiosk mode. I'd also log other information like the user and date and time it was scanned in.

  13. #13
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    It's very simple to describe each step of the process, but learning to properly or even functionally pull them off takes time.

    The barcode part takes about as much knowledge as perhaps a "Teach Yourself VB in 24 Hours" book. With forum help you ought to be able to pull that off in 48 hours or so. We can't help you a lot because you need someone that knows BARCOM in order to show you specifically what to do. My experience with workplace packages like that is they tend to have exactly one user in the world so you won't likely find an expert. 99% of them simulate keyboard input, so if you can write an app with a TextBox you finished here. If you can't, 8-16 work-hours from now you can.

    The next part's the booger. You need to ask some data store if this barcode has been scanned before. If it has, you display an error. If it hasn't, you tell the data store to save that barcode so it knows it's been scanned. Ignoring the part that talks about the database, the logic is easy. On a button press, store "is it scanned" in a Boolean. If True, display error. If False, proceed. This logic is another 8-16 work-hours of thought and learning.

    But the part with the data store is tough. You need to learn to install and configure a SQL server somewhere. That might mean interacting with your company's IT and ensuring they open up the appropriate ports. It might mean having to fight them to install it at all. You'll also have to learn at least one of the many ways .NET talks to SQL servers. You'll also have to learn how to design SQL tables, and do so for the tables you need for this application. This paragraph alone could occupy a 50-page book. If you can do all of it within one week and understand how every step worked, you're doing great.

    Then you plug that knowledge into the rest of the application. This is trivial once you did all the other work.

    The reason we're balking at specific code examples is that big paragraph. That's a topic you need to spend a lot of time researching and learning. We can't write a one-page crash course to installing/maintaining a SQL server, designing databases/tables, and interacting with the database via VB .NET. There are entire books on that topic, and thousands of tutoirals available.

    It takes a lot of effort to make a code example AND include all the steps it will take to make it work on your machine. And if you haven't read the books/tutorials to have a 50/50 chance of being able to guess those steps, odds are you'll mess up on one and we'll have to spend hours figuring out what it was.

    Your boss needs a developer. Your developer was fired. There's a reason peoples' job title is "developer", and it tends to be related to having spent months and years acquiring the skills to make a job like this a 3-day project that can be finished in an ugly manner in less than a day. For a person who hasn't spent those months and years, I think "2 months" is an optimistic guideline, assuming your boss is fine with you spending 40 hours/week doing nothing but training for your new developer position. You don't have other duties, right?
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  14. #14
    Frenzied Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    1,104

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    I like what Sitten Spynne said about just do one thing. First make the windows form and a text box or something to accept input form the scanner.
    It sounds like you understand about SQL Servers. Can you get that set up without our help?
    I suggest moving forward on these two goals and tell us where you get stuck. Take 'em as they come.
    BTW an ORM DataTable is super easy after you have a table in the SQL Server. Drag and drop it on your ORM object. It will go quick.
    You don't need a text box for instance you could have the form itself take the keystrokes. I think it's the keypress event. You can just ingest them as they come. I suppose the typing emulation from the from the scanner will have some kind of special character or code for the end of the text like a tab or newline. Otherwise you can wait until the input stops.

  15. #15
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    If you dont need all the gadgets from a DBM you could also use datatables to read/write XML and reduce your learning curve by a longshot

  16. #16
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Hi ,

    another thing I don't see is where do you pull the Product from ?
    for example row1;Level2;place5

    If you don't need a system with coordinates(where is the Stock) at this time you will need it in the Future.

    regards
    Chris
    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.

  17. #17
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Yeah, XML would work...for a few days, or a few years. If you are writing 200 records per day, five days a week, you could end up with 50,000 records per year. At some point, an XML file will start bogging down. It's much easier than a DB because it could be as simple as this:
    Code:
    'Create the table (only has to be done the first time)
    Dim dt As New Datatable
    dt.Columns.Add("BarCode",GetType(string))
    Once that's been done, then you can read/write the table to an XML file with the ReadXML/WriteXML functions. Searching the datatable can be done in a whole variety of different ways:

    1) Looping through each row (fastest, but takes the most code).
    2) LINQ (maybe the slowest, looks cool)
    3) .Select method (decent speed, simplest to write)
    4) DataView (about as simple as .Select, about the same performance).
    5) Order the thing, then use a binary search (REALLY fast as long as the sorting isn't done in a way that kills the performance).

    However, I tend to agree with what Sitten said. When I first saw this thread, I knew your boss was doomed to disappointment. It's just too much to ask in such a short time unless the person has done the same things before, and has a grasp of all the pieces. Frankly, with no experience whatsoever with that kind of barcode reader, I might take longer than that just figuring out how to interact with the hardware.
    My usual boring signature: Nothing

  18. #18
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Once that's been done, then you can read/write the table to an XML file with the ReadXML/WriteXML functions. Searching the datatable can be done in a whole variety of different ways:

    1) Looping through each row (fastest, but takes the most code).
    2) LINQ (maybe the slowest, looks cool)
    3) .Select method (decent speed, simplest to write)
    4) DataView (about as simple as .Select, about the same performance).
    5) Order the thing, then use a binary search (REALLY fast as long as the sorting isn't done in a way that kills the performance).
    The BindingSource.Find method is real good.
    Code:
            Dim BSPosition As Integer = bs.Find("ValueColumn", textbox1.Text)
            If BSPosition >= 0 Then
                'Found the scanned value, do things with it
                MsgBox(DirectCast(bs(BSPosition), DataRowView)("ValueColumn"))
            Else
                'Did not find the value, add it
                bs.AddNew()
                DirectCast(bs.Current, DataRowView)("ValueColumn") = textbox1.Text
            End If

  19. #19
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    At some point, an XML file will start bogging down.
    I've been pondering this. I swear Ive had better performance from XML than MSSQL with the same rowcount, in fact I've always thought XML was the fastest data access.

  20. #20
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    a simple textfile would be as easy as this:

    Code:
        Private Sub StoreData(Path As String, BarcodeList As List(Of String))
            IO.File.WriteAllLines(Path, BarcodeList)
        End Sub
    
        Private Function LoadData(Path As String) As List(Of String)
            Return IO.File.ReadAllLines(Path).ToList
        End Function
    and a use case:
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim lt As List(Of String) = Enumerable.Range(1, 400000).Select(Function(i) i.ToString("0000000000")).ToList
            StoreData("c:\kill\test.txt", lt)
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim lt As List(Of String) = LoadData("c:\kill\test.txt")
    
            Dim sSearch As String = "0000400001"
            Dim isFound As Boolean = lt.Contains(sSearch)
            MessageBox.Show(String.Format("{0} was {1}found!", sSearch, If(isFound, "", "not ")))
        End Sub
    this is 400,000 rows which would serve you well 10yrs, 200d/yr, 200 scans/day

  21. #21

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Quote Originally Posted by digitalShaman View Post
    a simple textfile would be as easy as this:

    Code:
        Private Sub StoreData(Path As String, BarcodeList As List(Of String))
            IO.File.WriteAllLines(Path, BarcodeList)
        End Sub
    
        Private Function LoadData(Path As String) As List(Of String)
            Return IO.File.ReadAllLines(Path).ToList
        End Function
    and a use case:
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim lt As List(Of String) = Enumerable.Range(1, 400000).Select(Function(i) i.ToString("0000000000")).ToList
            StoreData("c:\kill\test.txt", lt)
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim lt As List(Of String) = LoadData("c:\kill\test.txt")
    
            Dim sSearch As String = "0000400001"
            Dim isFound As Boolean = lt.Contains(sSearch)
            MessageBox.Show(String.Format("{0} was {1}found!", sSearch, If(isFound, "", "not ")))
        End Sub
    this is 400,000 rows which would serve you well 10yrs, 200d/yr, 200 scans/day
    Thanks for the reply! I currently have a Windows Application Form in VB.Net with a text box for a place for them to scan the barcode. I am wondering what the Button 1 and Button 2 would be for? Also, I am confused about what you mean by textfile. Do you mean I can put the first code in a text document and save it as a .bac?
    Last edited by learningsql; Mar 21st, 2018 at 03:01 PM.

  22. #22
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Quote Originally Posted by kpmc View Post
    I've been pondering this. I swear Ive had better performance from XML than MSSQL with the same rowcount, in fact I've always thought XML was the fastest data access.
    It may be, especially for simple data. If you are reading the whole thing into a datatable, then you will certainly get better performance when searching the datatable. That's all in memory. A DB read can't compete. However, at some point, the sheer size of the file will come into play. With all the RAM on modern computers, I'm not sure what size that would be. Most likely it would be once your XML file tops the gigabyte size. So, when would that be?

    If the barcode were about 10 characters, then that would take about 20 bytes, plus the XML tags for another 20 bytes, or so, and possibly some padding. That could be as little as 50 bytes per record, in which case an issue might not arise until you topped some 200 million records, give or take. Of course, that's for some very simple data, as described. A search on that (you did show a 6th way, which seems likely to be similar to .Select or the DataView.Find approach, and there are probably more) would be entirely in RAM, so it could be pretty quick.

    That all breaks down if the table got more complex, and completely breaks down if you end up with a relational system, but that's not the case here.
    My usual boring signature: Nothing

  23. #23
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Quote Originally Posted by learningsql View Post
    Thanks for the reply! I currently have a Windows Application Form in VB.Net with a text box for a place for them to scan the barcode. I am wondering what the Button 1 and Button 2 would be for? Also, I am confused about what you mean by textfile. Do you mean I can put the first code in a text document and save it as a .bac?
    Button2 is just an example of searching the file. You likely wouldn't do it quite like that. If the barcode reader populated the textbox (it really should be a label, as a textbox suggests the user can edit it, which you don't want), then you'd have a TextChanged event. Rather than Button2, that code would do well in the TextChanged event handler. However, the list(of String) that is being searched should be moved to form scope, cause there's no good reason to load it fresh every time you read a barcode. Have it load once in either the Load event handler, or the form constructor, then just search it in the TextChanged event handler.

    Button1 looks like a a test, to me. It fills a list with 400,000 strings, then writes it to a file, so it tests that writing that many is feasible. In practice, if you had the list(of String) at form scope, then whenever you read a barcode that was NOT found, you would just add that barcode to the list. When you saved the list to the file is up to you, but that StoreData method would do that.
    My usual boring signature: Nothing

  24. #24

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    7

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Quote Originally Posted by Shaggy Hiker View Post
    It may be, especially for simple data. If you are reading the whole thing into a datatable, then you will certainly get better performance when searching the datatable. That's all in memory. A DB read can't compete. However, at some point, the sheer size of the file will come into play. With all the RAM on modern computers, I'm not sure what size that would be. Most likely it would be once your XML file tops the gigabyte size. So, when would that be?

    If the barcode were about 10 characters, then that would take about 20 bytes, plus the XML tags for another 20 bytes, or so, and possibly some padding. That could be as little as 50 bytes per record, in which case an issue might not arise until you topped some 200 million records, give or take. Of course, that's for some very simple data, as described. A search on that (you did show a 6th way, which seems likely to be similar to .Select or the DataView.Find approach, and there are probably more) would be entirely in RAM, so it could be pretty quick.

    That all breaks down if the table got more complex, and completely breaks down if you end up with a relational system, but that's not the case here.
    Here is an example of a BSN LD512222817009
    So 13 characters in all. I think if the file were too large i could delete some that were first scanned.

  25. #25
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Well, then my estimation of size is a bit small, but not by all that much. So, and XML file would work. Back in #17, I showed a small example of creating a datatable. The datatable has a ReadXML and WriteXML method, and they are super simple to use. All they take as arguments are the file name (complete path, of course). No decisions to make. It's just:

    yourDatatable.ReadXML(yourFileName)

    to fill the table, and

    yourDatatable.WriteXML(yourFileName)

    to write the table.

    Frankly, that parts the easy part. The difficult part, as far as I'm concerned would be how to get the barcode into the textbox or label. Once you have that, then saving it the easy part. The problem is that reading that barcode is likely going to require some kind of SDK from the scanner manufacturer. Nobody can help much with that, unless somebody has some experience with that specific scanner...which seems a bit unlikely. Hopefully, the manufacturer has some good example/documentation.
    My usual boring signature: Nothing

  26. #26
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: Write Code to Alert Users if Duplicate Barcode has been scanned

    Every barcode reader I have ever implemented did not require some wonky software, it basically input such as a keyboard. Before I got too crazy writing some crazy app using manufacture libraries Id buy a $12 barcode reader from amazon. I could be missing something...

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