Barcodes using VB?

can i prototype a barcode using VB? is it possible to draw the lines? wat other ways can i use to create the barcode?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

i highly recommend to use a barcode font

look at: (follow the link to the download page) (but i think this is just a demo version)

using a font is the best way, cause you just place a label on your form, choose the barcode font, and set the caption of the control correct

theire are also some activeX controls to produce bar codes, i prefere barcode fonts, cause they are more flexible (can be used in almost any app)

or you use
Line [Step] (x1, y1) [Step] - (x2, y2), [color], [B][F]

to draw lines on the form / picture box ...
The width of the line drawn depends on the setting of the DrawWidth property. The way a line or box is drawn on the background depends on the setting of the DrawMode and DrawStyle properties.
I most positively can NOT recommend barcode fonts
 i have found that with cheap barcode reading systems they give a lot of errors
i have made my own barcode printing routine using the code 39 symbology and the vb drawing functions
If i use this to print a barcode with any laser or inktjet
any reader can read it
if printed to a good dotmatrix almost any reader can read it
furthermore if you use your own routine you can control every aspect of the barcode such as small bar,wide bar,inter character spacing ...etc

as heder said use
Line [Step] (x1, y1) [Step] - (x2, y2), [color], [B][F]
i did not check the above links i suppose you will find there code enough to do what you want if not i'll gladly post my code here

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

liese79Author Commented:
thx oreghe and pierrecampe...

well, i've downloaded the codes from the links provided above. but i've not tested them yet. thx... =)

pierrecampe, can u post ur codes here as well? thx.. =)

u guys take care ok? bye... all the best~
copy this code in a module
to test have a form with autoredraw=true
and background=white

and a commandbutton with in its click event:

Private Sub Command1_Click()
   PrintBarCode39 "PIERRECAMPE", 30, 600
End Sub


Type Barcode39
     Character As String * 1
     barcode As String * 10
End Type
Dim code39(1 To 44)  As Barcode39

Sub InitBarCode39()
   code39(1).Character = "1": code39(1).barcode = "LSSLSSSSLI"
   code39(2).Character = "2": code39(2).barcode = "SSLLSSSSLI"
   code39(3).Character = "3": code39(3).barcode = "LSLLSSSSSI"
   code39(4).Character = "4": code39(4).barcode = "SSSLLSSSLI"
   code39(5).Character = "5": code39(5).barcode = "LSSLLSSSSI"
   code39(6).Character = "6": code39(6).barcode = "SSLLLSSSSI"
   code39(7).Character = "7": code39(7).barcode = "SSSLSSLSLI"
   code39(8).Character = "8": code39(8).barcode = "LSSLSSLSSI"
   code39(9).Character = "9": code39(9).barcode = "SSLLSSLSSI"
   code39(10).Character = "0": code39(10).barcode = "SSSLLSLSSI"
   code39(11).Character = "A": code39(11).barcode = "LSSSSLSSLI"
   code39(12).Character = "B": code39(12).barcode = "SSLSSLSSLI"
   code39(13).Character = "C": code39(13).barcode = "LSLSSLSSSI"
   code39(14).Character = "D": code39(14).barcode = "SSSSLLSSLI"
   code39(15).Character = "E": code39(15).barcode = "LSSSLLSSSI"
   code39(16).Character = "F": code39(16).barcode = "SSLSLLSSSI"
   code39(17).Character = "G": code39(17).barcode = "SSSSSLLSLI"
   code39(18).Character = "H": code39(18).barcode = "LSSSSLLSSI"
   code39(19).Character = "I": code39(19).barcode = "SSLSSLLSSI"
   code39(20).Character = "J": code39(20).barcode = "SSSSLLLSSI"
   code39(21).Character = "K": code39(21).barcode = "LSSSSSSLLI"
   code39(22).Character = "L": code39(22).barcode = "SSLSSSSLLI"
   code39(23).Character = "M": code39(23).barcode = "LSLSSSSLSI"
   code39(24).Character = "N": code39(24).barcode = "SSSSLSSLLI"
   code39(25).Character = "O": code39(25).barcode = "LSSSLSSLSI"
   code39(26).Character = "P": code39(26).barcode = "SSLSLSSLSI"
   code39(27).Character = "Q": code39(27).barcode = "SSSSSSLLLI"
   code39(28).Character = "R": code39(28).barcode = "LSSSSSLLSI"
   code39(29).Character = "S": code39(29).barcode = "SSLSSSLLSI"
   code39(30).Character = "T": code39(30).barcode = "SSSSLSLLSI"
   code39(31).Character = "U": code39(31).barcode = "LLSSSSSSLI"
   code39(32).Character = "V": code39(32).barcode = "SLLSSSSSLI"
   code39(33).Character = "W": code39(33).barcode = "LLLSSSSSSI"
   code39(34).Character = "X": code39(34).barcode = "SLSSLSSSLI"
   code39(35).Character = "Y": code39(35).barcode = "LLSSLSSSSI"
   code39(36).Character = "Z": code39(36).barcode = "SLLSLSSSSI"
   code39(37).Character = "-": code39(37).barcode = "SLSSSSLSLI"
   code39(38).Character = ".": code39(38).barcode = "LLSSSSLSSI"
   code39(39).Character = " ": code39(39).barcode = "SLLSSSLSSI"
   code39(40).Character = "*": code39(40).barcode = "SLSSLSLSSI"
   code39(41).Character = "$": code39(41).barcode = "SLSLSLSSSI"
   code39(42).Character = "/": code39(42).barcode = "SLSLSSSLSI"
   code39(43).Character = "+": code39(43).barcode = "SLSSSLSLSI"
   code39(44).Character = "%": code39(44).barcode = "SSSLSLSLSI"
End Sub

Sub PrintBarCode39(Thetext, Smallbar, Theheight)
'!!!no comments on declaring variables please !!!
' to print to the printer or a picturebox use Printer.Line or Picture1.line instead of Form1.Line
' or add a variable specivying the device
' you can of course remove or add variables as you like
' this is the point you can tailor this to your EXACT needs
' this is just code to illustrate the principle

'Smallbar is the width of a small bar
'Theheight is the height of the barcode

startx = Form1.CurrentX  'where printing should start
starty = Form1.CurrentY
Oldstartx = startx

Largebar = Smallbar * 2.1  'the ratio between large and small bars
Intercharacterspace = Smallbar * 1 'the ratio between Intercharacterspacing and small bars
Newposition = startx
Colour = &HFFFFFF
ThetextWithStartAndStopChar = "*" & Thetext & "*" 'if start and stop chars are not needed dont use em
    For x = 1 To Len(ThetextWithStartAndStopChar)
        Chartosearch = Mid(ThetextWithStartAndStopChar, x, 1)
        Foundchar = ""
        For z = 1 To UBound(code39)
           If code39(z).Character = Chartosearch Then
              Foundchar = code39(z).barcode
           End If
        Next z
        If Len(Foundchar) Then
              For y = 1 To 10
                  Onechar = Mid(Foundchar, y, 1)
                  If Colour = &HFFFFFF Then       ' White ,to make this thing more generic we even draw white bars
                      Colour = &H0                ' Black
                      Colour = &HFFFFFF
                  End If
                  Select Case Onechar
                         Case "L" ' a large bar
                              Form1.Line (Newposition, starty)-Step(Largebar, Theheight), Colour, BF
                              Newposition = Newposition + Largebar
                         Case "S" ' a small bar
                              Form1.Line (Newposition, starty)-Step(Smallbar, Theheight), Colour, BF
                              Newposition = Newposition + Smallbar
                         Case "I" ' the Intercharacterspacing
                              Form1.Line (Newposition, starty)-Step(Intercharacterspace, Theheight), Colour, BF
                              Newposition = Newposition + Intercharacterspace
                         Case Else
                              ' an example of my VERY INTELLIGENT ERROR TRAPPING (grin)
                              MsgBox ("NO code 39")
                  End Select
            Next y
            Form1.Print Chartosearch; ' rem out for no human readable text
            MsgBox ("No code 39")
            Form1.Print "?";
        End If
    Next x
End Sub

If anyone has symbologys for other barcodes please post them here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you are printing the barcodes on a report, I agree with the FONTS solution.

If, however, you are printing the barcodes on a Label, there are loads of label printers out there with internal barcode fonts. These produce the best quality barcodes easiest.

I have used BarFonts to include a barcode on an Access report. But I do more labeling projects than Access projects, and each one uses a dedicted label printer.
excellent solution pierrecampe!
liese79Author Commented:
hi there everyone, pierrecampe, can u explain the way the bar code works? i don really understand it, how come some bars r bold compared to other 'thinner' ones? =)

take care, all the best~
Hi liese
ok i'll try
this is a code39 barcode also known as code 3 of 9
wich means that every character in its characterset is made of 9 bars,of wich 6 are small bars and 3 are wide bars
example the character "1" has the following bars: "LSSLSSSSLI"
in wich "L" stands for a large(wide,bold) bar and "S" stands for a small(thin) bar and the "I" stands for the intercharacter space(just as in printed text there has to be a space between the characters)
so you could say that in the code39 alfabet "LSSLSSSSL" is what "1" is in the human alfabet
these bars are drawn using the VB Line method
now the code39 alfabet is made up of the 44 characters you see in the code
there is a ratio between large and small bars and there is also a ratio between a small bar and the intercharspace
the ratio i have used here is large bars are 2.1 times wider then small bars
and the intercharspace is equal to the width of a small bar
I have found this to work very good
you could ofcourse change these ratio's
maybe what you mean is why are some small bars thinner than other small bars ?(and for large bars to)
that liese is this thing prints to a form and a form is on a screen and a screens resolution is not good enouch
if you print to a printer you will see that all the small bars have the same width(large bars to)
i'll try to explain this
on my screen a pixel is 15 twips so if i draw a line thats between 16 and 29 twips wide the screen driver has to make a desition if it will use 1 or 2 pixels
the morale dont bother with the screen
if you where to make a routine to draw barcodes to the screen you will have to do some very exact calculations
and after all a barcode is meant to be printed on a piece of paper or something

hope this was of some help if not feel free to ask
I have checked the above links and it turns out only one does not use fonts
but it uses a very intelligent and somewhat difficult to understand  solution representing each character as a binary
and an improvement to this routine using the api drawing methods wich is supposed to be 40 times faster
but what is 40 times faster then immediately ???
and a 40 times faster routine does not make the printer 40 times faster right?
so liese what you use is up to you
and if your client is rich and can afford expensive barcode readers and the royaltys on the fonts by all means use fonts they are very easy to use
If you want to be proud of what you do use VB

maybe some of the font makers ??? (you'l make a lot less money but then you'l probably go to heaven)

liese79Author Commented:
pierrecampe, thanks for explaing the whole thing to me.. =)) hey, how do i reduce the size of the whole barcode? hehehehe.. cos it's kinda too big for my form.. can i reduce the size of it?
thx.. =)

liese i dont mean to be rude but have you studied the code? do you understand it ?
some advice NEVER use code you do not understand this is a MAJOR cause of bugs and will only get you into trouble
please excuse for this tirade (i am an old man)
so ok:
PrintBarCode39 "PIERRECAMPE", 30, 600
the 30 in this statement is the width of a small bar
Largebar = Smallbar * 2.1  
this is the width of a large bar ie:2.1 x 30 = 63
so if you replace 30 with 15 the small bar will have a width of 15 and a large bar a width of 15 x 2.1 =31.5
this will make the barcode about half the width
further more you could reduce the ratio between large and small bar to say 1.5
and this will make it even less wide
the 600 is the height of the barcode
reduce it to 300 and the height will be half the original
but liese a barcode is meant to be printed to paper and to be read by a barcode reader
so may i suggest you do not print to the screen forget about the screen
liese play along a bit with these numbers on a printer until your barcode reader can read it every time
again i did not mean to be rude so if you have any more questions feel free to ask

liese79Author Commented:
thx... =) no, u r not being rude. i did study the codes, but somehow, i didnt really understand it (i'm not really an expert in coding)... well, now that i understand more bout ur codes, i would be able to reduce the size. =)
anyway, i'm only doing a prototype for an electronic stamp. i want to get ur permission to use these codes in my project. this is an academic project... i'm currently doing my honours project.
permission granted and success on your project
and thank you for teaching me some shorthand
liese79Author Commented:
thxxx.... =)))
for everything that u've posted here... =))
u take care, n all the best to u~

perhaps the following info will aid your quest for additional symbologies.....

Standards & Specifications

AIM USA ''Uniform Symbology Specifications'':
      Interleaved 2-of-5 (Item X5-1)
      Code 39 (Item X5-2)
      Codabar (Item X5-3)
      Code 128 (Item X5-4)
Available from:
      AIM USA
      634 Alpha Drive
      Pittsburgh, PA  15238-2802
      Phone: 412-963-8588
      Fax: 412-963-8753

AIM Europe ''Telepen Uniform Symbology Specification''
Available from:
      AIM Europe
      The Old Vicarage, Haley Hill
      Halifax, West Yorkshire, HX3 6XX, UK

Phone: 01422 368368
      Fax: 01422 355604

ANSI X3.182, ''Bar Code Print Quality - Guideline''
Available from:
      The American National Standards Institute
      11 West 42nd St., 13th Floor
      New York, NY  10036
      Phone: 212-642-4900
      Fax: 212-398-0023
Also available from AIM USA (address above).

CEN Specifications
Available from:
      Commission for European Normalization
      36 Rue de Stassart
      B-1050 Bruxelles
      Phone: (32) 2.519.68.11

Fax: (32) 2.519.68.19

EAN Specifications
Available from:
      EAN International
      Rue Royale 29
      B-1000 Bruxelles
      Phone: (32)
      Fax: (32)
Also available from EAN National Authorities around the world and AIM USA (address above).

U.P.C. Specifications
UCC/EAN-128 Application Identifier Standard
Application Identifier Standard For Shipping Container Codes
Available from:
      The Uniform Code Council, Inc.

7887 Washington Village Drive
      Suite 300
      Dayton, OH  45459
      Phone: 937-435-3870
      Fax: 937-435-7317

good luck & have fun!
thank you kfrick
I'll first try belgium (thats where i live)
Liese how about clicking on 'accept comment as answer'
seems like a good idea to me
liese79Author Commented:
Comment accepted as answer
liese79Author Commented:
hey pierrecampe... erm... i don know whether did i do the rite thing of accepting ur comment as answer o not... this is my first time... well, really want to thank u for all that u've taught me.. i'm sorry if i did the wrong thing during the procedure of accepting ur answers... thx .. take care of urself.. all the best!!
liese79Author Commented:
pierrecampe... how many points were added to u? how do i increase the points for u?
Liese this question now rates 10 points
so i suppose you gave me 100 points
dont give me more points
you could use your points in the future
Hi all .

How can I download free barcode fonts ( ex: Code 39 , Code 128 etc. ). That should not be demo version. I want only free download . If you are know the links please send to me .

Thanks All

Best regards .

PChandima .
Dear Expert " Pierrecampe "

                                      instead of  you give example, How do i write code to use combo box select a values from table
and generate to barcode? could you please help me to do?

Private Sub Command1_Click()
   PrintBarCode39 "PIERRECAMPE", 30, 600
End Sub

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.