New topic: 

CODE 39 Barcode Genarator

<http://forums.realsoftware.com/viewtopic.php?t=39284>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        basestring          Post subject: CODE 39 Barcode 
GenaratorPosted: Wed Jun 01, 2011 10:58 pm                         
Joined: Sat May 28, 2011 11:28 pm
Posts: 3                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

Code:  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

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
   
                             Top                 timhare          Post subject: 
Re: CODE 39 Barcode GenaratorPosted: Thu Jun 02, 2011 2:03 am                   
      
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 9867
Location: Portland, OR  USA                Or use a barcode font with 
DrawString.  Drawing your own barcodes is iffy at best.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to