Printing bar codes in Visual Basic

To print bar codes you must use the bar code functions in the supplied Visual Basic module (.BAS). Before you can use these new functions in your project, see Add our Visual Basic module in a project.

Example project

An example Visual Basic project is provided. The example contains a simple form.

The example uses the module functions that you will need to use.

The example allows you to enter text data and draw or print bar codes. You can also adjust parameters that affect the appearance of the bar code. 

Here are the functions / subroutines you will need to use or refer to;

Declare Function CIAX_2D_PDF417_COM Lib "CIAX2D32.DLL" (ByVal msg As String, ByVal ret As String, ByVal param As String, ByRef retlen As Long, ByVal err As String) As Long
Sub CIAX_2D_DRAW(o As Object, s As String, w As Integer, h As Integer)
Sub PrintExample()
Sub DrawExample()

CIAX_2D_PDF417_COM()

Function CIAX_2D_PDF417_COM() encodes any string messages in to a pattern string (e.g. "11111001100010011...") that uses 0 and 1 to represent a light and dark elements. 

Pattern strings are printed as a physical bar code using function CIAX_2D_DRAW() to convert the pattern string in to a series of graphics commands.

TIP: Open the example project and look at the PrintExample() subroutine, which makes use of function CIAX_2D_PDF417_COM() and CIAX_2D_DRAW().

TIP: To specify a specific printer, to use to print example bar codes, set SpecificPrinter to a string that contains all or part of the name of your chosen printer (e.g. "HP LaserJet 4050 T PCL 6").

Function CIAX_2D_PDF417_COM() is contained in a DLL. The Visual Basic declaration in module CIAXCOM.BAS allows you to use the function anywhere in your Visual Basic code.

Function CIAX_2D_PDF417_COM() takes the following arguments;

msg - message string to encode in the bar code.

ret -  the returned bar code pattern string.

param - a string listing parameters affecting the symbol (e.g. number of required columns, error correction level, etc.). For example, this "S0C3" would produce a symbol with Error Correction Level 0, with 3 columns.

Sn  Selects the Error Correction Level (0 >= n <= 9).
Cn  Specifies number of bar code symbol columns. Usually either C or R is specified, not both.
Rn  Specifies number of bar code symbol rows. Usually either C or R is specified, not both.
V  Produce bar code symbols with vertical quiet zones - above and below.
Z  Produce bar code symbols with horizontal quiet zones - left and right.

retlen - is the returned length of ret.

err - is any error message returned.

CIAX_2D_DRAW()

There is no need to modify this function. Function CIAX_2D_DRAW() is used to draw or print the bar code previously returned by CIAX_2D_PDF417_COM().

Function CIAX_2D_DRAW() takes the following arguments;

o - object (e.g. Picture, Printer, etc.) to draw / print the bar code on.

s - bar code pattern string returned from function CIAX_2D_PDF417_COM().

w - module width in pixels. This is the width of the smallest elements in the symbol.

h - module height in pixels. This is the height of each row.

Note: The example code shows how to use ScaleX and ScaleY functions to calculate accurate pixel values (for w and h) from measurements in millimeters.

In many cases you will know the resolution of the printer used to print the bar codes. In this case, you can achieve total control of the printed output by specifying w and h directly in fixed pixel values.

PrintExample()

This subroutine prints a bar code containing the text entered on the form and using the parameters entered on the form.

You should copy or modify this subroutine for use in your own projects.

DrawExample()

This subroutine is very similar to PrintExample() except it draws the bar code in a Picture object. Bar codes are not very useful displayed on the screen.

 


Copyright 2000 CIA (BAR CODES) UK. All rights reserved. Reproduction prohibited.