Microsoft KB Archive/37888

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 19:21, 12 August 2020 by X010 (talk | contribs) (X010 moved page Microsoft KB Archive/Q37888 to Microsoft KB Archive/37888 without leaving a redirect: Text replacement - "Microsoft KB Archive/Q" to "Microsoft KB Archive/")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to Send Three-Character Printer Control Codes in Ver. 1.x

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

1.07 1.10 1.12 MS-DOS

Summary: The code example below shows how to send three-character printer control codes to the printer from a COBOL Version 1.07, 1.10, or 1.12 program.

More Information: The decimal value sent to the printer must be the decimal equivalent of the concatenated hexadecimal number representing the sequence of control codes. For example, suppose you wish to set the left margin on a page to 20 columns for an Epson printer. The printer control code sequence is as follows: ESC+l+hh where l is the lowercase letter l, and hh is the number of columns. These codes have the following ASCII values: ESC is 1B hex, l is 6C hex, and 20 is 14 hex. When you concatenate these hexadecimal values into one number, you get 1B6C14 hex. You may use a calculator (or BASIC program) equipped with hexadecimal notation to convert this hexadecimal number into its decimal form; or you can convert it manually as follows: 1048576 = hex 1 in the sixth significant digit = 1 times 165 720896 = hex B in the fifth significant digit = 11 times 164 24576 = hex 6 in the fourth significant digit = 6 times 163 3072 = hex C in the third significant digit = 12 times 162 16 = hex 1 in the second significant digit = 1 times 161 + 4 = hex 4 in the first significant digit = 4 times 160
——————————————————————– 01797140 = hex 1B6C14 When using two-character control codes in COBOL Versions 1.x, the variable in the WORKING-STORAGE SECTION should be assigned this decimal value using a COMP-0. 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 1.x: sending three-character control codes
   *                    to the printer
   *       
   * Testing print capabilities
   *
    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(8) usage comp-4.
   *
    working-storage section.
    01 reset-code      pic 9(5)  value 06976 comp-0.
    01 threchr-code    pic 9(8)  value 01797140 comp-4.
   *
    procedure division.
    only-para.
        open output print-file.
        move "this line is normal" to print-rec.
        write print-rec.
   *
   ********************************************************
   * This area will send the printer code <esc> l chr$(n) *
   * to the printer and it will set the left margin to 20 *
   ********************************************************
   *
        display threchr-code upon printer-device.
        move "this lines left margin is moved" to print-rec.
        write rpint-rec.
   *
   * reset printer
   *
        display reset-code upon printer-device.
        move "this line is normal" to print-rec.
        write print-rec.
        close print-file.
    stop run.

Copyright Microsoft Corporation 1991.