Barcode Generator UPC

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Barcode Generator UPC

Post by Da_Elf » Fri Sep 22, 2017 11:28 pm

Based on this video. Experts can tell me my code is too long and there is an easier way to do it but i cant figure it out
https://www.youtube.com/watch?v=e6aR1k-ympo

can use some help making the text better

Code: Select all

on mouseUp
   put the text of fld "myCode" into myCode   
   gencode 2,myCode, "mygrp"
end mouseUp

on gencode barwidth myCode grpname
   if the length of myCode <> 12 then
      answer " Your code has to be 12 numbers"
      exit to top
   end if
   lock screen
   put x before myCode
   put x after char 7 in myCode
   put x after myCode
   if exists(grp grpname) then
      delete grp grpname
   end if
   create grp grpname
   
   
   put (barwidth * 95)+100 into borderwidthy
   create grc "bordergrc" in grp grpname
   set visible of grc "bordergrc" of grp grpname to false
   set the width of grc "bordergrc" of grp grpname to borderwidthy
   set the height of grc "bordergrc" of grp grpname to 200
   set the opaque of grc "bordergrc" of grp grpname to true
   set the linesize of grc "bordergrc" of grp grpname to 2
   set the backgroundColor of grc "bordergrc" of grp grpname to 255,255,255 
   
   
   put 400 into myY
   put 400 into myX
   put 1 into section
   put "3,7,7,7,7,7,7,5,7,7,7,7,7,7,3" into amounts
   put 1 into advance
   put empty into thenumberlist
   repeat for 15 times
      set itemDelimiter to comma
      put item section of amounts into repam
      put 1 into coloradvance
      repeat for repam times
         put "BCode"&advance into codename
         create grc codename in grp grpname
         set the width of grc codename of grp grpname to barwidth
         set the height of grc codename of grp grpname to 150
         set the loc of grc codename of grp grpname to myX,myY
         if section is 1 or section is 2 or section is 8 or section is 14 or section is 15 then
            set the height of grc codename of grp grpname to 150
         else
            set the height of grc codename of grp grpname to 125
         end if
         set the top of grc codename of grp grpname to myY
         set the opaque of grc codename of grp grpname to true
         set the linesize of grc codename of grp grpname to 0
         put char section of myCode into ournumb
         put sect(section,ournumb) into sectionColors
         put char coloradvance of sectionColors into barcolor
         put barcolor after thenumberlist
         if barcolor is 1 then
            set the backgroundColor of grc codename of grp grpname to 0,0,0
         else if barcolor is 0 then
            set the backgroundColor of grc codename of grp grpname to 255,255,255
         end if
         add barwidth to myX
         add 1 to advance
         add 1 to coloradvance
      end repeat
      add 1 to section
   end repeat
   
   put the loc of grp grpname into borderzpos
   set the loc of grc "bordergrc" of grp grpname to borderzpos
   set visible of grc "bordergrc" of grp grpname to true
   
   create fld "number1" in grp grpname
   set the text of fld "number1" of grp grpname to char 1 of the text of fld "myCode"
   set the textFont of fld "number1" of grp grpname to "Arial"
   set the textSize of fld "number1" of grp grpname to 20
   set showBorder of fld "number1" of grp grpname to false
   set opaque of fld "number1" of grp grpname to false
   set the width of fld "number1" of grp grpname to the formattedWidth of fld "number1" of grp grpname
   set the right of fld "number1" of grp grpname to the left of grc "BCode1" grp grpname
   set the bottom of fld "number1" of grp grpname to ((the bottom of grc "BCode1" of grp grpname) + 10)
   set the textAlign of fld "number1" of grp grpname to "center"
   set the margins of fld "number1" of grp grpname to 0

   
   create fld "number4" in grp grpname
   set the text of fld "number4" of grp grpname to char 12 of the text of fld "myCode"
   set the textFont of fld "number4" of grp grpname to "Arial"
   set the textSize of fld "number4" of grp grpname to 20
   set showBorder of fld "number4" of grp grpname to false
   set opaque of fld "number4" of grp grpname to false
   set the width of fld "number4" of grp grpname to the formattedWidth of fld "number1" of grp grpname
   set the left of fld "number4" of grp grpname to the right of grc "BCode95" grp grpname
   set the bottom of fld "number4" of grp grpname to ((the bottom of grc "BCode95" of grp grpname) + 10)
   set the textAlign of fld "number4" of grp grpname to "center"
   set the margins of fld "number4" of grp grpname to 0
   
   put (((5*7)*barwidth)-4) into fwidth
   create fld "number2" in grp grpname
   set the text of fld "number2" of grp grpname to char 2 to 6 of the text of fld "myCode"
   set the textFont of fld "number2" of grp grpname to "Arial"
   set the textSize of fld "number2" of grp grpname to 20
   set showBorder of fld "number2" of grp grpname to false
   set opaque of fld "number2" of grp grpname to false
   set the width of fld "number2" of grp grpname to fwidth
   set the left of fld "number2" of grp grpname to the right of grc "BCode11" grp grpname
   set the bottom of fld "number2" of grp grpname to ((the bottom of grc "BCode95" of grp grpname) + 10)
   set the textAlign of fld "number2" of grp grpname to "center"
   set the margins of fld "number2" of grp grpname to 0
   
   create fld "number3" in grp grpname
   set the text of fld "number3" of grp grpname to char 7 to 11 of the text of fld "myCode"
   set the textFont of fld "number3" of grp grpname to "Arial"
   set the textSize of fld "number3" of grp grpname to 20
   set showBorder of fld "number3" of grp grpname to false
   set opaque of fld "number3" of grp grpname to false
   set the width of fld "number3" of grp grpname to fwidth
   set the left of fld "number3" of grp grpname to the right of grc "BCode50" grp grpname
   set the bottom of fld "number3" of grp grpname to ((the bottom of grc "BCode95" of grp grpname) + 10)
   set the textAlign of fld "number3" of grp grpname to "center"
   set the margins of fld "number3" of grp grpname to 0
   unlock screen
end gencode

function sect section ournumb
   if section is 1 or section is 15 then
      put "101" into bcpattern
   else if section > 1 and section < 8 then
      if ournumb is 0 then
         put "0001101" into bcpattern
      else if ournumb is 1 then
         put "0011001" into bcpattern
      else if ournumb is 2 then
         put "0010011" into bcpattern
      else if ournumb is 3 then
         put "0111101" into bcpattern
      else if ournumb is 4 then
         put "0100011" into bcpattern
      else if ournumb is 5 then
         put "0110001" into bcpattern
      else if ournumb is 6 then
         put "0101111" into bcpattern
      else if ournumb is 7 then
         put "0111011" into bcpattern
      else if ournumb is 8 then
         put "0110111" into bcpattern
      else if ournumb is 9 then
         put "0001011" into bcpattern
      end if
   else if section is 8 then
      put "01010" into bcpattern
   else if section > 8 and section < 15 then
      if ournumb is 0 then
         put "1110010" into bcpattern
      else if ournumb is 1 then
         put "1100110" into bcpattern
      else if ournumb is 2 then
         put "1101100" into bcpattern
      else if ournumb is 3 then
         put "1000010" into bcpattern
      else if ournumb is 4 then
         put "1011100" into bcpattern
      else if ournumb is 5 then
         put "1001110" into bcpattern
      else if ournumb is 6 then
         put "1010000" into bcpattern
      else if ournumb is 7 then
         put "1000100" into bcpattern
      else if ournumb is 8 then
         put "1001000" into bcpattern
      else if ournumb is 9 then
         put "1110100" into bcpattern
      end if
end if
return bcpattern
end sect

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Barcode Generator UPC

Post by MaxV » Fri Sep 29, 2017 4:29 pm

Instead of writing all, create some templates and use clone or copy. :D
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Barcode Generator UPC

Post by bangkok » Sat Sep 30, 2017 1:26 pm

What about a barcode.... font ?
;-)

Code 39
Code 128
and even UPC

(quick search)
http://www.fontpalace.com/font-download/UPC-A/

Free. Easy to use (put your text in a field, and voilà, you get your barcode).

Many commercial fonts are available as well.

egolombek
Posts: 74
Joined: Thu Jan 30, 2020 2:11 pm

Re: Barcode Generator UPC

Post by egolombek » Mon Apr 13, 2020 8:40 am

On the one hand, this makes a beautiful looking barcode. But... it does not seem to scan which makes it less worthwhile. Thanks anyway!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”