|
Post by Rod on Apr 4, 2018 11:18:05 GMT
Here is a barcode to scan 'code128 barcode drawing 'http://www.barcodeisland.com/code128.phtml nomainwin
quietZone$ = "00000000000" startBsymbol$ = "11010010000" codeCsymbol$ = "10111011110" stopsymbol$ = "11000111010" termination$ = "11" codeCvalue = 99 dim barcodeimage$(127)'barcode images dim barcodevalues(127)'barcode value
'load character set B symbols i=0 while i<127 read i,v,b$ barcodeimage$(i)=b$ barcodevalues(i)=v wend
'open a small window graphicbox #bc.gb1, 20, 20, 300, 30 graphicbox #bc.gb2, 20, 100, 300, 30 textbox #bc.tb1, 20, 60, 300, 25 textbox #bc.tb2, 20, 150, 300, 25 WindowWidth = 400 WindowHeight = 300 open "Code128 Bar Code" for window as #bc print #bc, "trapclose [quit]"
'build a simple, uncompressed barcode 'calculate checksum and build barcode image 'the checksum starts as the initial startsymbol value 'to that we add the value of every subsequent symbol times 'its position in the message. Then mod 103 the total
message$="Liberty BASIC"
'select character set B ,B has upper and lower case alpha and numeric characters startBvalue=104 'start checksum calculation checksum=startBvalue barcode$="" for n = 1 to len(message$) checksum = checksum + n * barcodevalues(asc(mid$(message$,n,1))) barcode$ = barcode$ + barcodeimage$(asc(mid$(message$,n,1))) next
'calculate modulus checkdigit value checksum = checksum mod 103
'create total barcode image barcode$=quietZone$+startBsymbol$+barcode$+barcodeimage$(checksum+32)+stopsymbol$+termination$
'draw barcode #bc.gb1 "down ; fill white " x=0 for n = 1 to len(barcode$) if mid$(barcode$,n,1)="1" then #bc.gb1 "line ";x;" 0 ";x;" 40" end if x=x+1 next #bc.gb1 "flush" #bc.tb1 message$
'build a compressed image that packs numeric data 'this solution is unique to the following message and packs the 'last six numeric digits
message$="HI345678"
'select character set B startBvalue=104 'the example on the web site uses set A which is 103 so my checksum will vary 'from the example given on the web site but the code is still valid, you can 'build your barcode from any character set. checksum=startBvalue barcode$="" for n = 1 to 2 checksum = checksum + n * barcodevalues(asc(mid$(message$,n,1))) barcode$ = barcode$ + barcodeimage$(asc(mid$(message$,n,1))) next
'add the code 128 C symbol to change to packed numbers barcode$=barcode$+codeCsymbol$ checksum=checksum+codeCvalue*3
'now add the numbers in pairs cdx=4 for n = 3 to 7 step 2 checksum = checksum + cdx * barcodevalues(val(mid$(message$,n,2))+32) barcode$ = barcode$ + barcodeimage$(val(mid$(message$,n,2))+32) cdx=cdx+1 next
'calculate modulus checkdigit value checksum = checksum mod 103
'create total barcode image barcode$=quietZone$+startBsymbol$+barcode$+barcodeimage$(checksum)+stopsymbol$+termination$
'draw barcode #bc.gb2 "down ; fill white " x=0 for n = 1 to len(barcode$) if mid$(barcode$,n,1)="1" then #bc.gb2 "line ";x;" 0 ";x;" 40" end if x=x+1 next #bc.gb2 "flush" #bc.tb2 message$ wait
[quit] close #bc end
'barcode value and image table 'this is table B that has upper and lower case alpha and numeric 'table C is simply numeric pairs 00 01 etc so we dont need the data for that. 'Table A has upper case alpha and numeric but not lower case alpha. 'You will need to get Table A from the web site if you wish to use 'the special characters available in table A data 32,00,11011001100'space data 33,01,11001101100'! data 34,02,11001100110'" data 35,03,10010011000'# data 36,04,10010001100'$ data 37,05,10001001100'% data 38,06,10011001000'& data 39,07,10011000100'' data 40,08,10001100100'( data 41,09,11001001000') data 42,10,11001000100'* data 43,11,11000100100'+ data 44,12,10110011100', data 45,13,10011011100'- data 46,14,10011001110'. data 47,15,10111001100'/ data 48,16,10011101100'0 data 49,17,10011100110'1 data 50,18,11001110010'2 data 51,19,11001011100'3 data 52,20,11001001110'4 data 53,21,11011100100'5 data 54,22,11001110100'6 data 55,23,11101101110'7 data 56,24,11101001100'8 data 57,25,11100101100'9 data 58,26,11100100110': data 59,27,11101100100'; data 60,28,11100110100'< data 61,29,11100110010'= data 62,30,11011011000'> data 63,31,11011000110'? data 64,32,11000110110'@ data 65,33,10100011000'A data 66,34,10001011000'B data 67,35,10001000110'C data 68,36,10110001000'D data 69,37,10001101000'E data 70,38,10001100010'F data 71,39,11010001000'G data 72,40,11000101000'H data 73,41,11000100010'I data 74,42,10110111000'J data 75,43,10110001110'K data 76,44,10001101110'L data 77,45,10111011000'M data 78,46,10111000110'N data 79,47,10001110110'O data 80,48,11101110110'P data 81,49,11010001110'Q data 82,50,11000101110'R data 83,51,11011101000'S data 84,52,11011100010'T data 85,53,11011101110'U data 86,54,11101011000'V data 87,55,11101000110'W data 88,56,11100010110'X data 89,57,11101101000'Y data 90,58,11101100010'Z data 91,59,11100011010'[ data 92,60,11101111010'\ data 93,61,11001000010'] data 94,62,11110001010'^ data 95,63,10100110000'_ data 96,64,10100001100'` data 97,65,10010110000'a data 98,66,10010000110'b data 99,67,10000101100'c data 100,68,10000100110'd data 101,69,10110010000'e data 102,70,10110000100'f data 103,71,10011010000'g data 104,72,10011000010'h data 105,73,10000110100'i data 106,74,10000110010'j data 107,75,11000010010'k data 108,76,11001010000'l data 109,77,11110111010'm data 110,78,11000010100'n data 111,79,10001111010'o data 112,80,10100111100'p data 113,81,10010111100'q data 114,82,10010011110'r data 115,83,10111100100's data 116,84,10011110100't data 117,85,10011110010'u data 118,86,11110100100'v data 119,87,11110010100'w data 120,88,11110010010'x data 121,89,11011011110'y data 122,90,11011110110'z data 123,91,11110110110'{ data 124,92,10101111000'| data 125,93,10100011110'} data 126,94,10001011110'~ data 127,95,10111101000'DEL
|
|
|
Post by Rod on Apr 26, 2018 15:09:44 GMT
Managed to get this done at last. Needed to fix the checkdigit routine and the printing routine so that boxfilled was used. This ensures the lines are thick when size is used to alter the printing width.
'code128 barcode drawing 'http://www.barcodeisland.com/code128.phtml nomainwin
'these are constants for symbols used to define which table is used, 'change of table mid code and the quiet starting zone and stop symbol. quietZone$ = "00000000000" startAsymbol$ = "11010000100" '103 startBsymbol$ = "11010010000" '104 startCsymbol$ = "11010011100" '105 codeCsymbol$ = "10111011110" '99 codeBsymbol$ = "10111101110" '100 codeAsymbol$ = "11101011110" '101 stopsymbol$ = "1100011101011" 'initial checksum values startAvalue =103 startBvalue =104 startCvalue =105
'there are three tables a has uppercase alpha and control characters 'b has upper and lower case alpha, c is just for packing numeric 'data two characters to one byte
dim barcodeimage$(100)'barcode pattern dim barcodevalues(100,2)'barcode value 'a,b,c table asc value
'load character set A,B and C for i= 0 to 95 read a,b,c,b$ barcodeimage$(i)=b$ barcodevalues(i,0)=a barcodevalues(i,1)=b barcodevalues(i,2)=c next
'open a small window graphicbox #bc.gb1, 20, 20, 300, 30 graphicbox #bc.gb2, 20, 100, 300, 30 textbox #bc.tb1, 20, 60, 300, 25 textbox #bc.tb2, 20, 150, 300, 25 button #bc.b1, "Print",[print],UL 340, 20, 40,20 WindowWidth = 400 WindowHeight = 300 open "Code128 Bar Code" for window as #bc print #bc, "trapclose [quit]"
'first lets build a simple, uncompressed barcode 'We are using mixed upper and lower case so we choose 'table B to encode the message. 'the checksum starts as the initial startsymbol value for startBvalue 'to that we add the value of every subsequent symbol, times 'its position in the message. Then mod 103 the total
message$="Wikipedia"
'start checksum calculation checksum=startBvalue barcode$="" for n = 1 to len(message$) 'find the character in table B for v=0 to 95 if barcodevalues(v,1)=asc(mid$(message$,n,1)) then checksum = checksum + n * v barcode$ = barcode$ + barcodeimage$(v) exit for end if next next
'calculate modulus checkdigit value checksum = checksum mod 103
'create total barcode image barcode$=quietZone$+startBsymbol$+barcode$+barcodeimage$(checksum)+stopsymbol$
'draw barcode 'use box filled so that size changes on printer get thick black lines #bc.gb1 "down ; fill white ; backcolor black ; color black" x=0 for n = 1 to len(barcode$) if mid$(barcode$,n,1)="1" then #bc.gb1 "place ";x;" 0 ; boxfilled ";x+1;" 40" end if x=x+1 next #bc.gb1 "flush" #bc.tb1 message$
'build a compressed image that packs numeric data 'this solution packs the numeric digits two digits to one byte, so we 'will choose table C barcode$="" message$="123456789123"
checksum=startCvalue pos=1 'now add the numbers in pairs for n = 1 to 11 step 2 checksum = checksum + pos* val(mid$(message$,n,2)) barcode$ = barcode$ + barcodeimage$(val(mid$(message$,n,2))) pos=pos+1 next
'calculate modulus checkdigit value checksum = checksum mod 103
'create total barcode image barcode$=quietZone$+startCsymbol$+barcode$+barcodeimage$(checksum)+stopsymbol$
'draw barcode #bc.gb2 "down ; fill white ; backcolor black ; color black" x=0 for n = 1 to len(barcode$) if mid$(barcode$,n,1)="1" then #bc.gb2 "place ";x;" 0 ; boxfilled ";x+1;" 40" end if x=x+1 next #bc.gb2 "flush" #bc.tb2 message$ wait
[print] #bc.gb1 "print 400" #bc.gb2 "print 400" wait
[quit] close #bc end
'barcode value and image table ' a b c barcode data 32,32,0,"11011001100"'space data 33,33,1,"11001101100"'! data 34,34,2,"11001100110"'" data 35,35,3,"10010011000"'# data 36,36,4,"10010011000"'$ data 37,37,5,"10001001100"'% data 38,38,6,"10011001000"'& data 39,39,7,"10011000100"'' data 40,40,8,"10001100100"'( data 41,41,9,"11001001000"') data 42,42,10,"11001000100"'* data 43,43,11,"11000100100"'+ data 44,44,12,"10110011100"', data 45,45,13,"10011011100"'- data 46,46,14,"10011001110"'. data 47,47,15,"10111001100"'/ data 48,48,16,"10011101100"'0 data 49,49,17,"10011100110"'1 data 50,50,18,"11001110010"'2 data 51,51,19,"11001011100"'3 data 52,52,20,"11001001110"'4 data 53,53,21,"11011100100"'5 data 54,54,22,"11001110100"'6 data 55,55,23,"11101101110"'7 data 56,56,24,"11101001100"'8 data 57,57,25,"11100101100"'9 data 58,58,26,"11100100110"': data 59,59,27,"11101100100"'; data 60,60,28,"11100110100"'< data 61,61,29,"11100110010"'= data 62,62,30,"11011011000"'> data 63,63,31,"11011000110"'? data 64,64,32,"11000110110"'@ data 65,65,33,"10100011000"'A data 66,66,34,"10001011000"'B data 67,67,35,"10001000110"'C data 68,68,36,"10110001000"'D data 69,69,37,"10001101000"'E data 70,70,38,"10001100010"'F data 71,71,39,"11010001000"'G data 72,72,40,"11000101000"'H data 73,73,41,"11000100010"'I data 74,74,42,"10110111000"'J data 75,75,43,"10110001110"'K data 76,76,44,"10001101110"'L data 77,77,45,"10111011000"'M data 78,78,46,"10111000110"'N data 79,79,47,"10001110110"'O data 80,80,48,"11101110110"'P data 81,81,49,"11010001110"'Q data 82,82,50,"11000101110"'R data 83,83,51,"11011101000"'S data 84,84,52,"11011100010"'T data 85,85,53,"11011101110"'U data 86,86,54,"11101011000"'V data 87,87,55,"11101000110"'W data 88,88,56,"11100010110"'X data 89,89,57,"11101101000"'Y data 90,90,58,"11101100010"'Z data 91,91,59,"11100011010"'[ data 92,92,60,"11101111010"'\ data 93,93,61,"11001000010"'] data 94,94,62,"11110001010"'^ data 95,95,63,"10100110000"'_ data 0,96,64,"10100001100"'NULL ` table a then table b data 1,97,65,"10010110000"'SOH a data 2,98,66,"10010000110"'STX b data 3,99,67,"10000101100"'ETX c data 4,100,68,"10000100110"'EOT d data 5,101,69,"10110010000"'ENQ e data 6,102,70,"10110000100"'ACK f data 7,103,71,"10011010000"'BELL g data 8,104,72,"10011000010"'BS h data 9,105,73,"10000110100"'HT i data 10,106,74,"10000110010"'LF j data 11,107,75,"11000010010"'VT k data 12,108,76,"11001010000"'FF l data 13,109,77,"11110111010"'CR m data 14,110,78,"11000010100"'SO n data 15,111,79,"10001111010"'SI o data 16,112,80,"10100111100"'DLE p data 17,113,81,"10010111100"'DC1 q data 18,114,82,"10010011110"'DC2 r data 19,115,83,"10111100100"'DC3 s data 20,116,84,"10011110100"'DC4 t data 21,117,85,"10011110010"'NAK u data 22,118,86,"11110100100"'SYN v data 23,119,87,"11110010100"'ETB w data 24,120,88,"11110010010"'CAN x data 25,121,89,"11011011110"'EM y data 26,122,90,"11011110110"'SUB z data 27,123,91,"11110110110"'ESC { data 28,124,92,"10101111000"'FS | data 29,125,93,"10100011110"'GS } data 30,126,94,"10001011110"'RS ~ data 31,127,95,"10111101000"'US DEL
'the remaining codes as constants in the program 'not all are implemented '96=fnc3 '97=fnc2 '98=shift '99=code c '100=code b '101=code a '102=fnc1 '103=start a '104=start b '105=start c
|
|