Microsoft KB Archive/37890

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

COBOL 3.00-4.00: Sending Three-Character Printer Control Codes

PSS ID Number: Q37890 Article last modified on 04-25-1991

3.00 3.00a 4.00 | 3.00 3.00a 4.00 MS-DOS | OS/2

Summary: The following code example shows how to send three-character printer control codes to the printer from a COBOL version 3.00, 3.00a or 4.00 program. A sample program, PRINTESC.CBL, is included with Microsoft COBOL Professional Development System version 4.00. It can be found in the DEMO subdirectory of your COBOL directory. If you did not install the sample programs on your initial setup, you can use SETUP.EXE to select the “All sample programs” component, and then repeat the installation process with only the new component selected.

More Information: The code sent to the printer must be the concatenated hexadecimal number representing the sequence of control codes. For example, suppose you want 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 20 is 14 hex When you concatenate these hexadecimal values into one number, you get 1B6C14 hex. The example below, plus examples for other COBOL versions, are also included in an application note titled “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.  printcodefor3.
  *
  *Printer Control Codes for
  *Cobol 3.00 and 4.00
  *
   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  underline-rec   pic x(20).
   01  reset-rec       pic x(20).
   WORKING-STORAGE SECTION.
   77  name-strec      pic x(30).
   PROCEDURE DIVISION.
   P00-MAIN-ROUTINE.
       open output print-file.
  *
  *This hex code, <Esc>@, resets the printer
  *
       move x"1B40" to reset-rec.
       write print-rec from reset-rec.
       move "This line is not underlined" to name-strec.
       write print-rec from name-strec after advancing 2.
  *
  *The hex code below will set the left margin to 20.
  *The code is <Esc> l HEX(n)
  *
       move x"1B6C14" to underline-rec.
       write print-rec from underline-rec.
       move "This line's left margin is 20" to name-strec.
       write print-rec from name-strec after advancing 2.
  *
  *The hex code below will reset the printer.
  *The code is <Esc> @
  *
       move x"1B40" to underline-rec.
       write print-rec from underline-rec.
       close print-file.
   stop run.

Copyright Microsoft Corporation 1991.