LEADTOOLS Barcode (Leadtools.Barcode assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
Code Property
See Also 
Leadtools.Barcode Namespace > BarcodeException Class : Code Property



Gets or sets the code that caused the exception.

Syntax

Visual Basic (Declaration) 
Public Property Code As BarcodeExceptionCode
Visual Basic (Usage)Copy Code
Dim instance As BarcodeException
Dim value As BarcodeExceptionCode
 
instance.Code = value
 
value = instance.Code
C# 
public BarcodeExceptionCode Code {get; set;}
C++/CLI 
public:
property BarcodeExceptionCode Code {
   BarcodeExceptionCode get();
   void set (    BarcodeExceptionCode value);
}

Property Value

The exception code.

Example

Visual BasicCopy Code
Public Sub CodeExample()
      ' Load an image
      Dim codecs As RasterCodecs = New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "barcode1.tif"))

      ' Initialize barcodes
      Dim barEngine As BarcodeEngine = New BarcodeEngine()
      Dim searchRect As LeadRect = LeadRect.Empty
      Dim bar1d As Barcode1d = New Barcode1d()
      bar1d.Direction = BarcodeDirectionFlags.LeftToRight
      bar1d.Granularity = 9
      bar1d.MaximumLength = 3
      bar1d.MinimumLength = 1

      Try
         ' Try to read barcodes
         barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch Or BarcodeReadFlags.Markers, 0, bar1d, Nothing, Nothing)
      Catch ex As BarcodeException
         ' See if LEADTOOLS could not recognize this image format
         If ex.Code = BarcodeExceptionCode.Barcode1dLocked Then
            Console.WriteLine("You need to unlock barcode linear engine")
         Else
            ' Other LEADTOOLS Barcode error
            Console.WriteLine("Could not read barcodes, Leadtools code: {0}" & Constants.vbLf & "Message: {1}", ex.Code, ex.Message)
         End If
      Catch ex As Exception
         ' Other errors
         Console.WriteLine("Could not read barcodes {0}", ex.Message)
      End Try

   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void CodeExample()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;
      string fileName = Path.Combine(LEAD_VARS.ImagesDir, "barcode1.tif");
      RasterImage image = codecs.Load(fileName);

      // Initialize barcodes
      BarcodeEngine barEngine = new BarcodeEngine();
      LeadRect searchRect = LeadRect.Empty;
      Barcode1d bar1d = new Barcode1d();
      bar1d.Direction = BarcodeDirectionFlags.LeftToRight;
      bar1d.Granularity = 9;
      bar1d.MaximumLength = 3;
      bar1d.MinimumLength = 1;

      try
      {
         // Try to read barcodes
         barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch | BarcodeReadFlags.Markers, 0, bar1d, null, null);
      }
      catch (BarcodeException ex)
      {
         // See if LEADTOOLS could not recognize this image format
         if (ex.Code == BarcodeExceptionCode.Barcode1dLocked)
            Console.WriteLine("You need to unlock barcode linear engine");
         else
         {
            // Other LEADTOOLS Barcode error
            Console.WriteLine("Could not read barcodes, Leadtools code: {0}\nMessage: {1}", ex.Code, ex.Message);
         }
      }
      catch (Exception ex)
      {
         // Other errors
         Console.WriteLine("Could not read barcodes {0}", ex.Message);
      }

   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
public void CodeExample(RasterImage image)
{
   // Initialize barcodes
   BarcodeEngine barEngine = new BarcodeEngine();
   LeadRect searchRect = LeadRect.Empty;
   Barcode1d bar1d = new Barcode1d();
   bar1d.Direction = BarcodeDirectionFlags.LeftToRight;
   bar1d.Granularity = 9;
   bar1d.MaximumLength = 3;
   bar1d.MinimumLength = 1;
   try
   {
      // Try to read barcodes
      barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch | BarcodeReadFlags.Markers, 0, bar1d, null, null);
   }
   catch (BarcodeException ex)
   {
      // See if LEADTOOLS could not recognize this image format
      if (ex.Code == BarcodeExceptionCode.Barcode1dLocked)
         Console.WriteLine("You need to unlock barcode linear engine");
      else
      {
         // Other LEADTOOLS Barcode error
         Console.WriteLine("Could not read barcodes, Leadtools code: {0}\nMessage: {1}", ex.Code, ex.Message);
      }
   }
   catch (Exception ex)
   {
      // Other errors
      Console.WriteLine("Could not read barcodes {0}", ex.Message);
   }

}
SilverlightVBCopy Code
Public Sub CodeExample(ByVal image As RasterImage)
  ' Initialize barcodes
  Dim barEngine As BarcodeEngine = New BarcodeEngine()
  Dim searchRect As LeadRect = LeadRect.Empty
  Dim bar1d As Barcode1d = New Barcode1d()
  bar1d.Direction = BarcodeDirectionFlags.LeftToRight
  bar1d.Granularity = 9
  bar1d.MaximumLength = 3
  bar1d.MinimumLength = 1
  Try
    ' Try to read barcodes
    barEngine.Read(image, searchRect, BarcodeSearchTypeFlags.Barcode1dEan13, BarcodeUnit.ScanlinesPerPixels, BarcodeReadFlags.BlockSearch Or BarcodeReadFlags.Markers, 0, bar1d, Nothing, Nothing)
  Catch ex As BarcodeException
    ' See if LEADTOOLS could not recognize this image format
    If ex.Code = BarcodeExceptionCode.Barcode1dLocked Then
       Console.WriteLine("You need to unlock barcode linear engine")
    Else
       ' Other LEADTOOLS Barcode error
       Console.WriteLine("Could not read barcodes, Leadtools code: {0}" & Constants.vbLf & "Message: {1}", ex.Code, ex.Message)
    End If
  Catch ex As Exception
    ' Other errors
    Console.WriteLine("Could not read barcodes {0}", ex.Message)
  End Try

End Sub

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features