LEADTOOLS Barcode Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.23
Finding Duplicated Barcodes
  1. Start Visual Studio .NET.
  2. Start with the project that you created in Reading Bar Codes Tutorial
  3. Drag and drop a button in Form1. Change the following properties: Property Value: Name: btnFindDuplicate Text: Find Duplicate
  4. Add the following code for the btnFindDuplicate control’s click procedure:

    Visual Basic

                Private Sub btnFindDuplicate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindDuplicate.Click
                      Dim msg As String
                      Dim data As BarcodeData = _readBarData(0)
                      If data.IsDuplicated Then
                         Dim dupIndex As Integer = data.GetFirstDuplicatedIndex(0)
                         If dupIndex < 0 Then
                            msg = String.Format("Error occurred in the GetFirstDuplicatedIndex method. Error No. = {0}\n", dupIndex)
                            MessageBox.Show(Me, msg)
                         Else
                            ' Display the first duplicate barcode information.
                            data = _readBarData(dupIndex)
                            Dim barDataMsg As String = String.Format("Barcode Data = {0}\nType = {1}\nLeft = {2}\nTop = {3}\nRight = {4}\nBottom = {5}\n", _
                                                              BarcodeData.ConvertToStringArray(data.Data), _
                                                              data.SearchType, _
                                                              data.Location.Left, _
                                                              data.Location.Top, _
                                                              data.Location.Right, _
                                                              data.Location.Bottom)
                            MessageBox.Show(Me, barDataMsg)
                            dupIndex = data.GetNextDuplicated(dupIndex)
                            If dupIndex < 0 Then
                               msg = String.Format("Error occurred in the GetNextDuplicated method. Error No. = {0}\n", dupIndex)
                               MessageBox.Show(Me, msg)
                            Else
                               ' Display the next duplicate barcode information.
                               data = _readBarData(dupIndex)
                               barDataMsg = String.Format("Barcode Data = {0}\nType = {1}\nLeft = {2}\nTop = {3}\nRight = {4}\nBottom = {5}\n", _
                                                          BarcodeData.ConvertToStringArray(data.Data), _
                                                          data.SearchType, _
                                                          data.Location.Left, _
                                                          data.Location.Top, _
                                                          data.Location.Right, _
                                                          data.Location.Bottom)
                               MessageBox.Show(Me, barDataMsg)
                            End If
                         End If
                      Else
                         msg = String.Format("This Barcode is not duplicated ...")
                         MessageBox.Show(Me, msg)
                      End If
                End Sub
                
    

    C#

                private void btnFindDuplicate_Click(object sender, EventArgs e)
                {
                   string msg;
                   BarcodeData data = _readBarData[0];
                   if (data.IsDuplicated)
                   {
                      int dupIndex = data.GetFirstDuplicatedIndex(0);
                      if (dupIndex < 0)
                      {
                         msg = string.Format("Error occurred in the GetFirstDuplicatedIndex method. Error No. = {0}\n", dupIndex);
                         MessageBox.Show(this, msg);
                      }
                      else
                      {
                         /* Display the first duplicate barcode information. */
                         data = _readBarData[dupIndex];
                         string barDataMsg = string.Format("Barcode Data = {0}\nType = {1}\nLeft = {2}\nTop = {3}\nRight = {4}\nBottom {5}\n",
                                                           BarcodeData.ConvertToStringArray(data.Data),
                                                           data.SearchType,
                                                           data.Location.Left,
                                                           data.Location.Top,
                                                           data.Location.Right,
                                                           data.Location.Bottom);
                         MessageBox.Show(this, barDataMsg);
                         dupIndex = data.GetNextDuplicated(dupIndex);
                         if (dupIndex < 0)
                         {
                            msg = string.Format("Error occurred in the GetNextDuplicated method. Error No. = {0}\n", dupIndex);
                            MessageBox.Show(this, msg);
                         }
                         else
                         {
                            /* Display the next duplicate barcode information. */
                            data = _readBarData[dupIndex];
                            barDataMsg = string.Format("Barcode Data = {0}\nType = {1}\nLeft = {2}\nTop = {3}\nRight = {4}\nBottom = {5}\n",
                                                       BarcodeData.ConvertToStringArray(data.Data),
                                                       data.SearchType,
                                                       data.Location.Left,
                                                       data.Location.Top,
                                                       data.Location.Right,
                                                       data.Location.Bottom);
                            MessageBox.Show(this, barDataMsg);
                         }
                      }
                   }
                   else
                   {
                      msg = string.Format("This Barcode is not duplicated ...");
                      MessageBox.Show(this, msg);
                   }
                }
                
    
  5. Build, and Run the program to test it.