Question

I am attempting to take a string and convert it into a code 128 barcode in vb.net. I am a novice programmer and was wondering what some people thought would be the best design practices for accomplishing this.

A simple google search has yielded a few seemingly free solutions to this. http://www.onbarcode.com/vb_net/code-128-generator.html for example

I could also attempt to do this myself, but I'm not sure the exact method of converting strings into barcodes. I am going to keep looking into this but if someone knew this off the top of their head already it could save me some time.

Thanks in advance

Était-ce utile?

La solution

If you don't want to write any code for string conversion in barcode and don't want to buy an external component, you can use the ItextSharp library ( http://sourceforge.net/projects/itextsharp/ ) which is in my opinion the simplest way to achieve your goal. You can find several resources online and on stackoverflow too for itextsharp, mostly in c# but also vb.net.

for barcode generation vb.net code you can have a look here: http://professionalaspnet.com/archive/2008/11/09/A-Quick-and-Dirty-Bar-Code-Image-httpHandler.aspx

Autres conseils

Have a look at the following codeproject page - Barcode Image Generation Library

This allows you to generate a barcode image in your desired format from a string.

It should be enough to get you started

The following examples are taken from

http://www.onbarcode.com/tutorial/vb-net-barcode-generation.html

Generate barcode

 Dim barcode As OnBarcode.Barcode.Linear
    ' Create linear barcode object
    barcode = New OnBarcode.Barcode.Linear()
    ' Set barcode symbology type to Code-39
    barcode.Type = OnBarcode.Barcode.BarcodeType.CODE39
    ' Set barcode data to encode
    barcode.Data = "0123456789"
    ' Set barcode bar width (X    dimension) in pixel
    barcode.X = 1
    ' Set barcode bar height (Y dimension) in pixel
    barcode.Y = 60
    ' Draw & print generated barcode to png image file
    barcode.drawBarcode("C://vbnet-code39.png")

Draw and Print

 Dim qrCode As OnBarcode.Barcode.QRCode
    ' Create QRCode object
    qrCode = New OnBarcode.Barcode.QRCode()
    ' Set QR Code data to encode
    qrCode.Data = "VB.NET QRCode"
    ' Set QRCode data mode (QR-Code Barcode Settings)
    qrCode.DataMode = OnBarcode.Barcode.QRCodeDataMode.Auto
    ' Draw & print generated QR Code to jpeg image file
    qrCode.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg
    qrCode.drawBarcode("C://vbnet-qrcode.jpg")

You need to question your goal. That answer will drive your methodology.

  • Rapid development and completion
  • Learning experience
  • Cheap / free (sweat-equity excluded)

Your google link shows a product that displays sample code on that very page. What's wrong with that?

What is your target output? A report object, or will you print directly to the printer/label?

You can generate and output the code128 images in VB programming with this code . Refer to the following Visual Basic sample code,you can try to generate code128 in vb.net.

VB Sample code

 Dim code128 As KeepAutomation.Barcode.Bean.BarCode = New KeepAutomation.Barcode.Bean.BarCode
 code128.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto
 code128.CodeToEncode = "0128"

 'Apply checksum for Code 128 barcode.
 code128.ChecksumEnabled = True
 'Display checksum in the Code 128 barcode text
 code128.DisplayChecksum = True

 'Unit of measure, Pixel, Cm and Inch supported. 
 code128.BarcodeUnit = KeepAutomation.Barcode.BarcodeUnit.Pixel
 'Code 128 image resolution in DPI.
 code128.DPI = 72

 'Set Size for Generated Code 128 image

 'Code 128 bar module width (X dimention)
 code128.X = 2
 'Code 128 barcode image width (X dimention)
 code128.BarCodeWidth = 100
 'Code 128 bar module height (Y dimention)
 code128.Y = 60

 'Image left margin size, a 10X is automatically added according to specification.
 code128.LeftMargin = 0
 'Image right margin size, a 10X is automatically added according to specification.
 code128.RightMargin = 0
 'Code 128 image top margin size'
 code128.TopMargin = 0
 'Code 128 image bottom margin size'
 code128.BottomMargin = 0

 'Orientation, 90, 180, 270 degrees supported' Code 128 image bottom margin size
 code128.Orientation = KeepAutomation.Barcode.Orientation.Degree0
 'Code 128 image formats in Png, Gif, Jpeg/Jpg, Tiff, Bmp/Bitmap, etc.
 code128.ImageFormat = System.Drawing.Imaging.ImageFormat.Png

 'Set Code 128 human readable text style

 code128.DisplayText = True
 code128.TextFont = New Drawing.Font("Arial", 10.0F, Drawing.FontStyle.Regular)
 'Space between barcode and text
 code128.TextMargin = 6

 code128.generateBarcodeToImageFile("C://code128-vb-net.png")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top