Real Software Forums
http://forums.realsoftware.com/

CODE 39 Barcode Genarator
http://forums.realsoftware.com/viewtopic.php?f=21&t=39284
Page 1 of 1

Author:  basestring [ Wed Jun 01, 2011 10:58 pm ]
Post subject:  CODE 39 Barcode Genarator

Hi,

I'm building an application that works with CODE39 Barcode.
For people that want to genarate barcode, can use this function with a canvas controll

here is the Fuction
Name: Create_Barcode
Prameters: barcode as string
Return type: String

dim newbarcode as string
dim x as integer
newbarcode = "010010100Q" //Start Symbole Q = Quiet Zone (narrow Blank bar)
// 1 = wide 0 = narrow
// say Letter A = 100001001Q this means wide black, narrow blank, narrow black, narrow blank, narrow Black, Wide Blank,
// narrow black, narrow blank, wide Black and Q as a narrow Blank line for a Intercharacter gap
// this makes 5 black bars for eacht Charecter
// like + is black and - is blank Q is gap
// Q++-+-+--+-++Q = Latter A
barcode = Uppercase(barcode)
for x=1 to len(barcode)
if mid(barcode,x,1) = "0" then
newbarcode = newbarcode + "000110100Q"
end if
if mid(barcode,x,1) = "1" then
newbarcode = newbarcode + "100100001Q"
end if
if mid(barcode,x,1) = "2" then
newbarcode = newbarcode + "001100001Q"
end if
if mid(barcode,x,1) = "3" then
newbarcode = newbarcode + "101100000Q"
end if
if mid(barcode,x,1) = "4" then
newbarcode = newbarcode + "000110001Q"
end if
if mid(barcode,x,1) = "5" then
newbarcode = newbarcode + "100110000Q"
end if
if mid(barcode,x,1) = "6" then
newbarcode = newbarcode + "001110000Q"
end if
if mid(barcode,x,1) = "7" then
newbarcode = newbarcode + "000100101Q"
end if
if mid(barcode,x,1) = "8" then
newbarcode = newbarcode + "100100100Q"
end if
if mid(barcode,x,1) = "9" then
newbarcode = newbarcode + "101100000Q"
end if
if mid(barcode,x,1) = "A" then
newbarcode = newbarcode + "100001001Q"
end if
if mid(barcode,x,1) = "B" then
newbarcode = newbarcode + "001001001Q"
end if
if mid(barcode,x,1) = "C" then
newbarcode = newbarcode + "101001000Q"
end if
if mid(barcode,x,1) = "D" then
newbarcode = newbarcode + "000011001Q"
end if
if mid(barcode,x,1) = "E" then
newbarcode = newbarcode + "100011000Q"
end if
if mid(barcode,x,1) = "F" then
newbarcode = newbarcode + "001011000Q"
end if
if mid(barcode,x,1) = "G" then
newbarcode = newbarcode + "000001101Q"
end if
if mid(barcode,x,1) = "H" then
newbarcode = newbarcode + "100001100Q"
end if
if mid(barcode,x,1) = "I" then
newbarcode = newbarcode + "001001100Q"
end if
if mid(barcode,x,1) = "J" then
newbarcode = newbarcode + "000011100Q"
end if
if mid(barcode,x,1) = "K" then
newbarcode = newbarcode + "100000011Q"
end if
if mid(barcode,x,1) = "L" then
newbarcode = newbarcode + "001000011Q"
end if
if mid(barcode,x,1) = "M" then
newbarcode = newbarcode + "101000010Q"
end if
if mid(barcode,x,1) = "N" then
newbarcode = newbarcode + "000010011Q"
end if
if mid(barcode,x,1) = "O" then
newbarcode = newbarcode + "100010010Q"
end if
if mid(barcode,x,1) = "P" then
newbarcode = newbarcode + "001010010Q"
end if
if mid(barcode,x,1) = "Q" then
newbarcode = newbarcode + "000000111Q"
end if
if mid(barcode,x,1) = "R" then
newbarcode = newbarcode + "1000000110"
end if
if mid(barcode,x,1) = "S" then
newbarcode = newbarcode + "001000110Q"
end if
if mid(barcode,x,1) = "T" then
newbarcode = newbarcode + "000010110Q"
end if
if mid(barcode,x,1) = "U" then
newbarcode = newbarcode + "110000001Q"
end if
if mid(barcode,x,1) = "V" then
newbarcode = newbarcode + "011000001Q"
end if
if mid(barcode,x,1) = "W" then
newbarcode = newbarcode + "111000000Q"
end if
if mid(barcode,x,1) = "X" then
newbarcode = newbarcode + "010010001Q"
end if
if mid(barcode,x,1) = "Y" then
newbarcode = newbarcode + "110010000Q"
end if
if mid(barcode,x,1) = "Z" then
newbarcode = newbarcode + "011010000Q"
end if

if mid(barcode,x,1) = "-" then
newbarcode = newbarcode + "010000101Q"
end if
if mid(barcode,x,1) = "." then
newbarcode = newbarcode + "110000100Q"
end if
if mid(barcode,x,1) = " " then
newbarcode = newbarcode + "011000100Q" //Space
end if
if mid(barcode,x,1) = "/" then
newbarcode = newbarcode + "010100010Q"
end if
if mid(barcode,x,1) = "+" then
newbarcode = newbarcode + "010001010Q"
end if
if mid(barcode,x,1) = "%" then
newbarcode = newbarcode + "000101010Q"
end if
next x
newbarcode = newbarcode + "010010100" //End Symbole
return newbarcode


for the form, i have a textfield1 where you can type the next or numbers for the Barcode, a canvas1 with a height of 100 (width will change in the code) and a button with the following code

const White = &cffffff
const Black = &c000000
dim barcode as string
dim barcode_picture as Graphics
dim barcodesize as integer
dim x as Integer
dim drawpos as integer


barcode = Create_Barcode (TextField1.text)
barcodesize=20
for x =1 to len(barcode)
if mid(barcode,x,1) = "0" then barcodesize = barcodesize + 1
if mid(barcode,x,1) = "Q" then barcodesize = barcodesize + 1
if mid(barcode,x,1) = "1" then barcodesize = barcodesize + 2
next x


canvas1.Width = barcodesize * 2
barcodesize = barcodesize * 2
canvas1.graphics.ForeColor = white
canvas1.Refresh

for x=1 to 20
canvas1.Graphics.DrawLine x,1,x,100
next x
Canvas1.Graphics.ForeColor=black
drawpos = 21

for x = 1 to len(barcode)

if mid(barcode,x,1) = "0" then
canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1
canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1
if canvas1.graphics.ForeColor = white then
canvas1.graphics.ForeColor = black
else
canvas1.graphics.ForeColor = white
end if
end if
if mid(barcode,x,1) = "1" then
canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1

canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1

canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1

canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1
if canvas1.graphics.ForeColor = white then
canvas1.graphics.ForeColor = black
else
canvas1.graphics.ForeColor = white
end if
end if
if mid(barcode,x,1) = "Q" then
canvas1.graphics.ForeColor = white
canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1
canvas1.Graphics.DrawLine drawpos,1,drawpos,100
drawpos = drawpos+1
canvas1.graphics.ForeColor = black
end if
next x
canvas1.graphics.ForeColor = white
for x = drawpos to drawpos + 20
canvas1.Graphics.DrawLine x,1,x,100
next x

Author:  timhare [ Thu Jun 02, 2011 2:03 am ]
Post subject:  Re: CODE 39 Barcode Genarator

Or use a barcode font with DrawString. Drawing your own barcodes is iffy at best.

Author:  swort [ Thu Jun 02, 2011 9:57 am ]
Post subject:  Re: CODE 39 Barcode Genarator

Can i add this function with your permission to the DutchTools (public MIT licence) module ?

Author:  basestring [ Thu Jun 02, 2011 4:32 pm ]
Post subject:  Re: CODE 39 Barcode Genarator

Sure, no problem

Author:  Goofie [ Fri Jun 03, 2011 12:40 am ]
Post subject:  Re: CODE 39 Barcode Genarator

Thanks for sharing your code, it's usefull and gives insight in how barcodes work.
:D

Author:  Akiland [ Tue Mar 13, 2012 1:14 am ]
Post subject:  Re: CODE 39 Barcode Genarator

Hi, Awesome job!

Do you think it will support interleaved 2 of 5 barcodes soon? :)

Author:  NaNdummy [ Thu Mar 22, 2012 11:35 am ]
Post subject:  Re: CODE 39 Barcode Genarator

Can I use it for commercial use? I can add you to the credits if you want it.

Author:  kirkgray [ Thu Mar 22, 2012 3:16 pm ]
Post subject:  Re: CODE 39 Barcode Genarator

Perhaps a Select Case statement is in order:

...

for x = 1 to len(barcode)

Select Case mid(barcode, x, 1)
Case "0"
newbarcode = newbarcode + "000110100Q"

Case "1"
newbarcode = newbarcode + "100100001Q"

Case "2"
newbarcode = newbarcode + "001100001Q"

Case "3"
newbarcode = newbarcode + "101100000Q"

Case "4"
newbarcode = newbarcode + "000110001Q"

Case "5"
newbarcode = newbarcode + "100110000Q"

Case "6"
newbarcode = newbarcode + "001110000Q"

Case "7"
newbarcode = newbarcode + "000100101Q"

Case "8"
newbarcode = newbarcode + "100100100Q"

Case "9"
newbarcode = newbarcode + "101100000Q"

Case "A"
newbarcode = newbarcode + "100001001Q"

Case "B"
newbarcode = newbarcode + "001001001Q"

Case "C"
newbarcode = newbarcode + "101001000Q"

Case "D"
newbarcode = newbarcode + "000011001Q"

Case "E"
newbarcode = newbarcode + "100011000Q"

Case "F"
newbarcode = newbarcode + "001011000Q"

Case "G"
newbarcode = newbarcode + "000001101Q"

Case "H"
newbarcode = newbarcode + "100001100Q"

Case "I"
newbarcode = newbarcode + "001001100Q"

Case "J"
newbarcode = newbarcode + "000011100Q"

Case "K"
newbarcode = newbarcode + "100000011Q"

Case "L"
newbarcode = newbarcode + "001000011Q"

Case "M"
newbarcode = newbarcode + "101000010Q"

Case "N"
newbarcode = newbarcode + "000010011Q"

Case "O"
newbarcode = newbarcode + "100010010Q"

Case "P"
newbarcode = newbarcode + "001010010Q"

Case "Q"
newbarcode = newbarcode + "000000111Q"

Case "R"
newbarcode = newbarcode + "1000000110"

Case "S"
newbarcode = newbarcode + "001000110Q"

Case "T"
newbarcode = newbarcode + "000010110Q"

Case "U"
newbarcode = newbarcode + "110000001Q"

Case "V"
newbarcode = newbarcode + "011000001Q"

Case "W"
newbarcode = newbarcode + "111000000Q"

Case "X"
newbarcode = newbarcode + "010010001Q"

Case "Y"
newbarcode = newbarcode + "110010000Q"

Case "Z"
newbarcode = newbarcode + "011010000Q"

Case "-"
newbarcode = newbarcode + "010000101Q"

Case "."
newbarcode = newbarcode + "110000100Q"

Case " "
newbarcode = newbarcode + "011000100Q" //Space

Case "/"
newbarcode = newbarcode + "010100010Q"

Case "+"
newbarcode = newbarcode + "010001010Q"

Case "%"
newbarcode = newbarcode + "000101010Q"

End Select

next x

...

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/