Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Barcodes using VB?

Posted on 2000-07-09
24
Medium Priority
?
1,451 Views
Last Modified: 2013-11-18
can i prototype a barcode using VB? is it possible to draw the lines? wat other ways can i use to create the barcode?
0
Comment
Question by:liese79
  • 9
  • 8
  • 2
  • +5
24 Comments
 
LVL 1

Expert Comment

by:heder
ID: 3256193
i highly recommend to use a barcode font
(truetype)

look at:
http://www.adams1.com/pub/russadam/fonts.html

http://www.fontware.co.uk/ean13.htm (follow the link to the download page)
http://www.riversedge.com/
http://www.softseek.com/Graphics_and_Drawing/Fonts/Barcodes/D_22649_index.html (but i think this is just a demo version)
http://www.abri.com/fonts.html


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.
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3261750
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
 


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:liese79
ID: 3274972
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~
0
 
LVL 6

Accepted Solution

by:
pierrecampe earned 300 total points
ID: 3282133
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()
   InitBarCode39
   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
                  Else
                      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
        Else
            MsgBox ("No code 39")
            Form1.Print "?";
        End If
    Next x
End Sub

*********************************************************************************
If anyone has symbologys for other barcodes please post them here
0
 
LVL 3

Expert Comment

by:kfrick
ID: 3282890
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.
0
 
LVL 2

Expert Comment

by:brookman
ID: 3289613
excellent solution pierrecampe!
0
 

Author Comment

by:liese79
ID: 3317650
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~
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3319350
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
COME TO THINK OF SOMETHING
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
Greetings
   
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3320199
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

AGAIN IF SOMEONE KNOWS THE SYMBOLOGIES OF OTHER BARCODES PLEASE POST THEM HERE
maybe some of the font makers ??? (you'l make a lot less money but then you'l probably go to heaven)

0
 

Author Comment

by:liese79
ID: 3328712
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(lisa)
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3330135
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
greetings

 
 
0
 

Author Comment

by:liese79
ID: 3343896
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.
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3344399
permission granted and success on your project
and thank you for teaching me some shorthand
0
 

Author Comment

by:liese79
ID: 3345354
thxxx.... =)))
for everything that u've posted here... =))
u take care, n all the best to u~
=)
0
 
LVL 3

Expert Comment

by:kfrick
ID: 3351734
PC.....

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
      Belgium
      Phone: (32) 2.519.68.11

Fax: (32) 2.519.68.19

EAN Specifications
Available from:
      EAN International
      Rue Royale 29
      B-1000 Bruxelles
      Belgium
      Phone: (32) 2.218.76.74
      Fax: (32) 2.218.75.85
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!
-kf
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3357290
thank you kfrick
I'll first try belgium (thats where i live)
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3456020
Liese how about clicking on 'accept comment as answer'
seems like a good idea to me
0
 

Author Comment

by:liese79
ID: 3465814
Comment accepted as answer
0
 

Author Comment

by:liese79
ID: 3465861
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!!
0
 

Author Comment

by:liese79
ID: 3466396
pierrecampe... how many points were added to u? how do i increase the points for u?
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 3467075
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
0
 

Expert Comment

by:PChandima
ID: 11386846
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 .
0
 

Expert Comment

by:tarinter
ID: 13064182
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()
   InitBarCode39
   PrintBarCode39 "PIERRECAMPE", 30, 600
End Sub

Thank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn about the eCommerce marketing trends for the year ahead.
Do online retailers and e-commerce sites even need to bother with the season? Is it lucrative to update and prepare your site for Black Friday and Cyber Monday shoppers? We'll find out now.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question