Microsoft KB Archive/37885

How to Send Two-Character Printer Control Codes in Version 1.x

PSS ID Number: Q37885 Article last modified on 02-13-1991

1.07 1.10 1.12 MS-DOS

Summary: The program below shows how to send two-character printer control codes to the printer from programs compiled in Microsoft COBOL Versions 1.x. Please refer to your printer manual for a listing of the control codes for your printer.

More Information: The value sent to the printer must be the decimal equivalent of the concatenated hexadecimal number representing the sequence of control codes. ESC+E is the standard Epson printer control code to turn on boldface type. In hexadecimal representation, ESC is 1B hex, and the letter E is 45 hex. When you concatenate these hexadecimal codes, you get 1B45 hex. 1B45 hex is equal to a decimal value of 6981. When using two-character control codes, you should assign this decimal value (6981) to a COMP-0 variable (an integer of two bytes) in the WORKING-STORAGE SECTION. A COMP-4 variable should be used for three-character control codes, because the three-character control sequence requires an integer of 4 bytes. The example below, plus examples for later versions, are included in an application note entitled “Cobol 1.x-4.00 Printer Control Codes,” which can be obtained from Microsoft Product Support Services. The following is a code example:

identification division. program-id. print. * * COBOL VERSION 1.X: sending two-character control codes *                   to the printer environment division. configuration section. special-names. printer is printer-device. input-output section. file-control. select print-file assign to printer. *  data division. file section. fd print-file label records omitted linage is 56 lines. 01 print-rec pic x(80). *  working-storage section. * Epson printer reset = ESC+@ = hex 1B40 = 6976 decimal 01 reset-code   pic 9(4)   value 6976 comp-0. * Epson printer boldface on = ESC+E = 1B45 hex = 6981 decimal 01 twochr-code  pic 9(4)   value 6981 comp-0. *    procedure division. s000-mainline. open output print-file. display ' program &quot;print&quot; now beginning' upon printer-device. display ' ' upon printer-device. display reset-code upon printer-device. * Turn boldface on by sending ESC+E (1B45 hex) to Epson printer: display print-code upon printer-device. move &quot;this is line 1&quot; to print-rec. write print-rec. move &quot;this is line 2&quot; to print-rec. write print-rec. move &quot;this is line 3&quot; to print-rec. write print-rec. move &quot;this is line 4&quot; to print-rec. write print-rec. move &quot;this is line 5&quot; to print-rec. write print-rec. * * Reset printer, thus turning boldface off, by  * sending ESC+F (1B46 hex) to Epson printer: display reset-code upon printer-device. *      move &quot;this is line 6&quot; to print-rec. write print-rec. close print-file. stop run. Copyright Microsoft Corporation 1991.