Microsoft KB Archive/37886

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

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

2.00 2.10 2.20 MS-DOS

Summary: The following program for COBOL Versions 2.x shows how to send a two-character control code sequence to a printer. 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 sequence 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 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 other COBOL 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 2.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. 01 print-rec pic x(80). 01 cntl-rec     pic 9(4) usage comp-0. 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. only-para. open output print-file. move &quot;this line is not emphasized&quot; to print-rec. write print-rec. ************************************                 * Direct printer to print boldface * ************************************ *       write cntl-rec from reset-code before advancing 0. write cntl-rec from print-code before advancing 0. *            move &quot;this line is emphasized&quot; to print-rec. write print-rec. * * reset printer: write cntl-rec from reset-code before advancing 0. move &quot;this line is not emphasized&quot; to print-rec. write print-rec. close print-file. stop run. Copyright Microsoft Corporation 1991.