home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / CODE39C.ZIP / CODE39.PRG
Encoding:
Text File  |  1988-05-06  |  14.7 KB  |  378 lines

  1. **************************************************************************
  2. * Program...: CODE39.PRG
  3. * Version...: 1.0
  4. * Function..: Prints 3 of 9 barcodes
  5. *
  6. * Source....: Clipper (Summer '87)
  7. * Libraries.: CLIPPER.LIB  (c) Nantucket Corporation (Summer '87)
  8. *             EXTEND.LIB   (c) Nantucket Corporation (Summer '87)
  9. *
  10. * Author....: George T. Neill
  11. *             2140 Main Street
  12. *             La Crosse, WI  54601
  13. *
  14. * Created...: May 5, 1988  at 10:21 am
  15. * Copyright.: None, released to the public domain as is with no express
  16. *             or implied warranty as to suitability or accuracy of this
  17. *             program.  The author shall not be held liable for any 
  18. *             damages, either direct or non-direct, arising from the use
  19. *             of this program.  This program may be modified and/or
  20. *             included in any program without any consideration to the
  21. *             author.
  22. **************************************************************************
  23. * Revisions:
  24. * Date        Time   Who   Change Description
  25. * ───────────────────────────────────────────────────────────────────────-
  26. *
  27. **************************************************************************
  28. **************************************************************************
  29. *****                 CODE 3-of-9 BAR CODE  GENERATOR                *****
  30. *****                 *******************************                *****
  31. *****      This program will generate standard 3-of-9 bar code       *****
  32. *****      on any dot matrix printer which is compatable with        *****
  33. *****      an Epson/IBM graphics printer or HP LaserJet.             *****
  34. *****                 ******************************                 *****
  35. *****                      -  SPECIFICATIONS -                       *****
  36. **                                                                      **
  37. **                         W                                 N          **
  38. **                |  Nominal Width  | Nominal Width  | Nominal Ratio    **
  39. **     Density    |       of        |      of        |      of          **
  40. **   (Characters/ | Narrow Bars and | Wide Bars and  | Wide to Narrow   **
  41. **      Inch)     | Spaces (Inches) | Spaces (Inches)| Element Width    **
  42. **   -------------+-----------------+----------------+----------------  **
  43. **      5.730     |     0.0125      |     0.0315     |      2.52        **
  44. **   -------------+-----------------+----------------+----------------  **
  45. **                                                                      **
  46. *****                 ******************************                 *****
  47. *****  Code 3-of-9 was developed in 1974 by Dr. David C. Allais of   *****
  48. *****  Interface Mechanisms, Inc.  It has been adopted as the        *****
  49. *****  standard bar code symbology of the Department of Defence      *****
  50. *****  (MIL-STD-1189) and is the most widely used alphanumeric bar   *****
  51. *****  code in use.  Code 3-of-9 is so called because the original   *****
  52. *****  concept provided for 39 data characters.  The name also       *****
  53. *****  describes the structure of the code which has 3 wide elements *****
  54. *****  out of a total of 9.                                          *****
  55. *****                                                                *****
  56. *****  This program was written solely for information purposes to   *****
  57. *****  demonstrate the structure of code 3-of-9.  The author is      *****
  58. *****  not responsible for any damages incurred through the use of   *****
  59. *****  this program.                                                 *****
  60. *****                                                                *****
  61. *****                           Bill Wood  Milwaukee, WI   05/18/85  *****
  62. **************************************************************************
  63. **************************************************************************
  64. *****                                                                *****
  65. *****  This dBase code originated from a basic program written by    *****  
  66. *****  Bill Wood of Milwaukee, WI in May of 1985.  I have, of course,*****  
  67. *****  converted it to dBase and added support for the HP LaserJet.  *****  
  68. *****                                                                *****
  69. *****  Because of the wide variety and quality of bar code readers   *****
  70. *****  and barcode print quality when using a dot matrix printer, I  *****
  71. *****  strongly recommend using a laser printer for your barcodes.   *****
  72. *****  Also, the you will get 7 characters per inch on the laser as  *****
  73. *****  opposed to 5.6 cpi on a dot matrix.                           *****
  74. *****                                                                *****
  75. *****  The LaserJet barcodes are generated using the pattern fill    *****
  76. *****  functions and do not require the use of any font cartridges   *****
  77. *****  or soft fonts.  The tricky part of using this method is       *****
  78. *****  following the HP cusor location on the printed page.  Please  *****
  79. *****  refer to the HP LaserJet Technical Reference Manual for a     *****
  80. *****  thorough explanation of this.  Currently, the program is      *****
  81. *****  setup to print at 6 lines per inch.  That is, a height of 1   *****
  82. *****  is equal to one line.                                         *****
  83. *****                                                                *****
  84. *****  The program requires two functions, the printer setup, and    *****
  85. *****  the barcode creation.  The printer setup defines the          *****
  86. *****  components of the barcode and the barcode creation builds     *****
  87. *****  the barcode from a passed character string.  Using this       *****
  88. *****  program as an example you should be able to generate a        *****
  89. *****  barcode routine for any printer or barcode symbology.         *****
  90. *****                                                                *****
  91. *****  Good Luck,                                                    *****
  92. *****        George T. Neill                                         *****
  93. **************************************************************************
  94. **************************************************************************
  95.  
  96.  
  97. ***** Program Setup *****
  98. clear screen
  99. public esc,null,printer,height
  100.  
  101. esc = chr(27)
  102. null = ""
  103.  
  104. @ 01,01 say [Code 39 Barcode Generator]
  105.  
  106. ***** get printer type *****
  107. * default to two line LaserJet barcode
  108. printer   = "L"
  109. height    = 2
  110.  
  111. @ 03,01 say [Print on (E)pson or (L)aserJet?] ;
  112.         get m->PRINTER ;
  113.         picture '@!'; 
  114.         valid printer$'EL'
  115.  
  116. @ 04,01 say [Enter Height of Barcode (1-4)] ;
  117.         get m->HEIGHT ;
  118.         picture '9' ;
  119.         range 1,4
  120. read
  121.  
  122. if printer = "L"
  123.    do setup_hp
  124.  
  125. elseif printer = "E"
  126.    do setup_epson
  127.  
  128. endif
  129.  
  130. ***** Define CODE 3of9 Characer Set *****  
  131. do DEF_CODE39
  132.  
  133. ***** Get text to print and print barcode *****
  134. stay = .T.
  135. do while stay
  136.    ***** Create empty variable.  The length is arbitrary as there is *****
  137.    ***** no defined maximum length of a 3of9 barcode. *****
  138.    message = space(25)
  139.  
  140.    @ 07,01 say [Enter text to print ] ;
  141.            get m->MESSAGE ;
  142.            picture '@K!'
  143.    read
  144.  
  145.    if empty(m->MESSAGE)
  146.       ***** exit on no message text
  147.       stay = .F.
  148.       loop
  149.    endif
  150.  
  151.    ***** Prepend and append required asterik's to trimmed message *****
  152.    m->MESSAGE = "*"+trim(m->MESSAGE)+"*"
  153.  
  154.    set device to print
  155.    ***** print barcoded m->MESSAGE *****
  156.    @ prow()+height,00 say barcode(m->MESSAGE)
  157.  
  158.    ***** Print message text below barcode *****
  159.    @ prow()+if(printer="L",height,0),int(len(m->MESSAGE)/4) say  m->MESSAGE
  160.    set device to screen
  161.  
  162.    ***** Check for page eject *****
  163.    ***** (necessary to see what you've done on a laserjet) *****
  164.    eject = .F.
  165.    @ 08,01 say [Eject?] get eject picture [Y]
  166.    read
  167.    if eject
  168.       eject
  169.    endif
  170.  
  171. enddo
  172.  
  173. return
  174. ***** End of File CODE39 *****
  175.  
  176.  
  177. *****************
  178. ***
  179. ***   Function:  Barcode()
  180. ***    Purpose:  Creates Code39 barcode from character string
  181. *** Parameters:  Character String
  182. ***    Returns:  String converted to barcode
  183. ***      Notes:  Requires the following variables:
  184. ***           :  
  185. ***           :      All printers:
  186. ***           :         nb = narrow bar character
  187. ***           :         wb = wide bar character
  188. ***           :         ns = narrow space
  189. ***           :         ws = wide space
  190. ***           :  
  191. ***           :      HP LaserJet:
  192. ***           :         start = Beginning cursor position adjustment
  193. ***           :         end   = Ending cursor position adjustment
  194. ***           :  
  195. ***           :      Epson/IBM Printers:
  196. ***           :         height = height of barcode in lines
  197. ***           :         n1 & n2 = calculated dot graphics length
  198. ***           :  
  199. *****************
  200. function barcode
  201.    parameters m->MESSAGE
  202.    code = ""
  203.  
  204.    do case
  205.       case printer = "L"
  206.          * read message character at a time and build barcode
  207.          for i = 1 to len(m->MESSAGE)
  208.             letter = substr(m->MESSAGE,i,1)
  209.             code = code + if(at(letter,chars)=0,letter,char[at(letter,chars)]) + NS
  210.          next
  211.          code = start + code + end
  212.  
  213.       case printer = "E"
  214.          for h = 1 to height
  215.             for i = 1 to len(m->MESSAGE)
  216.                letter = substr(m->MESSAGE,i,1)
  217.  
  218.                * build barcoded string
  219.                code = if(at(letter,chars)=0,letter,char[at(letter,chars)]) + NS
  220.  
  221.                * print barcode character at a time on Epson
  222.                printcode(esc + chr(76) + chr(N1) + chr(N2) + code)
  223.             next
  224.  
  225.             * perform 23/216 line feed
  226.             printcode(esc+chr(74)+chr(23)+chr(13))
  227.          next
  228.  
  229.          * perform 5/216 line feed
  230.          printcode(esc+chr(74)+chr(5)+chr(13))
  231.  
  232.          * reset printer to turn off graphics and reset to 10cpi
  233.          printcode(esc+"@")
  234.  
  235.    endcase
  236.  
  237. return code
  238. ***** End of Function(BARCODE) *****
  239.  
  240.  
  241. *****************
  242. ***
  243. ***  Procedure:  Setup_HP
  244. ***    Purpose:  Defines characters for HP LaserJet
  245. *** Parameters:  None
  246. ***    Returns:  Initialized Public variables
  247. ***
  248. *****************
  249.  
  250. procedure setup_hp
  251.    public nb,wb,ns,ws,start,end
  252.    *** define bars and spaces for HP LaserJet II
  253.    small_bar = 3                                 && number of points per bar
  254.    wide_bar = round(small_bar * 2.25,0)          && 2.25 x small_bar
  255.    dpl = 50                                      && dots per line 300dpi/6lpi = 50dpl
  256.  
  257.    nb = esc+"*c"+transform(small_bar,'99')+"a"+alltrim(str(height*dpl))+"b0P"+esc+"*p+"+transform(small_bar,'99')+"X"
  258.    wb = esc+"*c"+transform(wide_bar,'99')+"a"+alltrim(str(height*dpl))+"b0P"+esc+"*p+"+transform(wide_bar,'99')+"X"
  259.    ns = esc+"*p+"+transform(small_bar,'99')+"X"
  260.    ws = esc+"*p+"+transform(wide_bar,'99')+"X"
  261.  
  262.    *** adjust cusor position to start at top of line and return to bottom of line
  263.    start = esc+"*p-50Y"
  264.    end = esc+"*p+50Y"
  265.  
  266. return
  267. ***** End of Procedure(SETUP_HP) *****
  268.  
  269. *****************
  270. ***
  271. ***  Procedure:  Setup_Epson
  272. ***    Purpose:  Defines characters for Espon or IBM Graphics printer
  273. *** Parameters:  None
  274. ***    Returns:  Initialized Public variables
  275. ***
  276. *****************
  277.  
  278. procedure setup_epson
  279.    public nb,wb,ns,ws,n1,n2
  280.    ***** define Epson bars and spaces
  281.    ns = chr(0) + chr(0)
  282.    ws = chr(0) + chr(0) + chr(0) + chr(0)
  283.    nb = chr(255)
  284.    wb = chr(255) + chr(255) + chr(255)
  285.    
  286.    ***** set printer to 2/216 lines per inch
  287.    printcode(esc+chr(51)+chr(2))                 
  288.  
  289.    ***** calculate N1 and N2 values for dot graphics command
  290.    cols = 21
  291.    N1 = cols % 256                               && modulus 
  292.    N2 = INT(cols/256)
  293.  
  294. return   
  295. ***** End of Procedure(SETUP_EPSON) *****
  296.  
  297.  
  298. *****************
  299. ***
  300. ***  Procedure:  Def_Code39
  301. ***    Purpose:  Define character set for CODE39
  302. *** Parameters:  None
  303. ***    Returns:  Initialized Public variables and array
  304. ***
  305. *****************
  306.  
  307. procedure def_code39
  308. public char[44], chars
  309.  
  310. chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"
  311. CHAR[01] = WB+NS+NB+WS+NB+NS+NB+NS+WB       && "1"
  312. CHAR[02] = NB+NS+WB+WS+NB+NS+NB+NS+WB       && "2"
  313. CHAR[03] = WB+NS+WB+WS+NB+NS+NB+NS+NB       && "3"
  314. CHAR[04] = NB+NS+NB+WS+WB+NS+NB+NS+WB       && "4"
  315. CHAR[05] = WB+NS+NB+WS+WB+NS+NB+NS+NB       && "5"
  316. CHAR[06] = NB+NS+WB+WS+WB+NS+NB+NS+NB       && "6"
  317. CHAR[07] = NB+NS+NB+WS+NB+NS+WB+NS+WB       && "7"
  318. CHAR[08] = WB+NS+NB+WS+NB+NS+WB+NS+NB       && "8"
  319. CHAR[09] = NB+NS+WB+WS+NB+NS+WB+NS+NB       && "9"
  320. CHAR[10] = NB+NS+NB+WS+WB+NS+WB+NS+NB       && "0"
  321. CHAR[11] = WB+NS+NB+NS+NB+WS+NB+NS+WB       && "A"
  322. CHAR[12] = NB+NS+WB+NS+NB+WS+NB+NS+WB       && "B"
  323. CHAR[13] = WB+NS+WB+NS+NB+WS+NB+NS+NB       && "C"
  324. CHAR[14] = NB+NS+NB+NS+WB+WS+NB+NS+WB       && "D"
  325. CHAR[15] = WB+NS+NB+NS+WB+WS+NB+NS+NB       && "E"
  326. CHAR[16] = NB+NS+WB+NS+WB+WS+NB+NS+NB       && "F"
  327. CHAR[17] = NB+NS+NB+NS+NB+WS+WB+NS+WB       && "G"
  328. CHAR[18] = WB+NS+NB+NS+NB+WS+WB+NS+NB       && "H"
  329. CHAR[19] = NB+NS+WB+NS+NB+WS+WB+NS+NB       && "I"
  330. CHAR[20] = NB+NS+NB+NS+WB+WS+WB+NS+NB       && "J"
  331. CHAR[21] = WB+NS+NB+NS+NB+NS+NB+WS+WB       && "K"
  332. CHAR[22] = NB+NS+WB+NS+NB+NS+NB+WS+WB       && "L"
  333. CHAR[23] = WB+NS+WB+NS+NB+NS+NB+WS+NB       && "M"
  334. CHAR[24] = NB+NS+NB+NS+WB+NS+NB+WS+WB       && "N"
  335. CHAR[25] = WB+NS+NB+NS+WB+NS+NB+WS+NB       && "O"
  336. CHAR[26] = NB+NS+WB+NS+WB+NS+NB+WS+NB       && "P"
  337. CHAR[27] = NB+NS+NB+NS+NB+NS+WB+WS+WB       && "Q"
  338. CHAR[28] = WB+NS+NB+NS+NB+NS+WB+WS+NB       && "R"
  339. CHAR[29] = NB+NS+WB+NS+NB+NS+WB+WS+NB       && "S"
  340. CHAR[30] = NB+NS+NB+NS+WB+NS+WB+WS+NB       && "T"
  341. CHAR[31] = WB+WS+NB+NS+NB+NS+NB+NS+WB       && "U"
  342. CHAR[32] = NB+WS+WB+NS+NB+NS+NB+NS+WB       && "V"
  343. CHAR[33] = WB+WS+WB+NS+NB+NS+NB+NS+NB       && "W"
  344. CHAR[34] = NB+WS+NB+NS+WB+NS+NB+NS+WB       && "X"
  345. CHAR[35] = WB+WS+NB+NS+WB+NS+NB+NS+NB       && "Y"
  346. CHAR[36] = NB+WS+WB+NS+WB+NS+NB+NS+NB       && "Z"
  347. CHAR[37] = NB+WS+NB+NS+NB+NS+WB+NS+WB       && "-"
  348. CHAR[38] = WB+WS+NB+NS+NB+NS+WB+NS+NB       && "."
  349. CHAR[39] = NB+WS+WB+NS+NB+NS+WB+NS+NB       && " "
  350. CHAR[40] = NB+WS+NB+NS+WB+NS+WB+NS+NB       && "*"
  351. CHAR[41] = NB+WS+NB+WS+NB+WS+NB+NS+NB       && "$"
  352. CHAR[42] = NB+WS+NB+WS+NB+NS+NB+WS+NB       && "/"
  353. CHAR[43] = NB+WS+NB+NS+NB+WS+NB+WS+NB       && "+"
  354. CHAR[44] = NB+NS+NB+WS+NB+WS+NB+WS+NB       && "%"
  355.  
  356. return
  357. ***** End of Procedure(DEF_CODE39) *****
  358.  
  359. *****************
  360. ***
  361. ***   Function:  Printcode
  362. ***    Purpose:  Sends escape codes to printer
  363. *** Parameters:  Character string or escape sequence
  364. ***    Returns:  Nothing
  365. ***
  366. *****************
  367.  
  368. function printcode
  369.    parameters code
  370.    set console off
  371.    set print on
  372.    ?? code
  373.    set print off
  374.    set console on
  375. return null
  376. ***** End of Function(PRINTCODE) *****
  377.  
  378.