Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Jun 27, 2017 9:02 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: CODE 39 Barcode Genarator
PostPosted: Wed Jun 01, 2011 10:58 pm 
Offline
User avatar

Joined: Sat May 28, 2011 11:28 pm
Posts: 130
Location: Beijing China
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

_________________
For great Music got to my podcast Website!!!
http://podcast.1945mf-china.com


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Thu Jun 02, 2011 2:03 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Or use a barcode font with DrawString. Drawing your own barcodes is iffy at best.


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Thu Jun 02, 2011 9:57 am 
Offline

Joined: Mon May 31, 2010 5:35 am
Posts: 2412
Location: Netherlands
Can i add this function with your permission to the DutchTools (public MIT licence) module ?

_________________
SWORT™
- Windows Vista, Windows XP, Windows 7, Linux Mint 11 and Mac OSX Lion
- REAL Studio Enterprise(latest) and WEB Edition(latest)
- Plugins (MBS Complete, ToringoLib, Einhugur, VanHoek + Some open source plugins)
For Dutch User Groups ask me to enter!


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Thu Jun 02, 2011 4:32 pm 
Offline
User avatar

Joined: Sat May 28, 2011 11:28 pm
Posts: 130
Location: Beijing China
Sure, no problem

_________________
For great Music got to my podcast Website!!!
http://podcast.1945mf-china.com


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Fri Jun 03, 2011 12:40 am 
Offline

Joined: Tue Nov 13, 2007 11:48 am
Posts: 189
Location: Belgium
Thanks for sharing your code, it's usefull and gives insight in how barcodes work.
:D


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Tue Mar 13, 2012 1:14 am 
Offline
User avatar

Joined: Tue Jan 04, 2011 3:02 am
Posts: 1236
Location: Jönköping, Sweden
Hi, Awesome job!

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

_________________
Image http://www.linkedin.com/in/albinkiland
Dev. iMac 27" + 2x22" LG (2.8GHz Intel Core i7, 12GB RAM, 120GB SSD) OS X 10.8
Xojo Pro 2013r1


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Thu Mar 22, 2012 11:35 am 
Offline

Joined: Thu Dec 01, 2011 2:13 pm
Posts: 288
Can I use it for commercial use? I can add you to the credits if you want it.

_________________
Mac OS X 10.3-10.8
Windows 2000 (I know it sucks)
Windows Server 2007

You want a bunch of new classes and web styles? realstudiodevspot.com (search there for Web Styles Plugin)
Folderitem is too hard? File Bin Class
I hate cows.


Top
 Profile  
Reply with quote  
 Post subject: Re: CODE 39 Barcode Genarator
PostPosted: Thu Mar 22, 2012 3:16 pm 
Offline

Joined: Mon Dec 26, 2005 1:42 pm
Posts: 326
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

...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group