Microsoft KB Archive/37096

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 19:21, 12 August 2020 by X010 (talk | contribs) (X010 moved page Microsoft KB Archive/Q37096 to Microsoft KB Archive/37096 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 Print COBOL 3.0 to 4.0 Control Codes to HP LaserJet

PSS ID Number: Q37096 Article last modified on 04-20-1993

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

The information in this article applies to:
- Microsoft COBOL for MS-DOS, versions 3.0, 3.0a, and 4.0 - Microsoft COBOL for OS/2, versions 3.0, 3.0a, and 4.0

Summary: This article contains an example of how to send printer control codes to an HP LaserJet printer from a COBOL version 3.0, 3.0a, or 4.0 program. This program can also be used as a basis for sending control codes to other types of printers. Note that different printers usually have entirely different control codes. Please refer to your printer manual to determine the control codes necessary for different effects. Your printer manual may list the control codes in hexadecimal notation. In COBOL version 3.0, 3.0a, or 4.0 you can use the MOVE statement to place a hexadecimal literal into a COBOL data item (this cannot be done in earlier versions, which do not support hexadecimal notation). Note that the x before the number surrounded by double quotation marks denotes that the following number is a hexadecimal literal (for example, MOVE x“1B” TO PRINT-REC).

More Information: A sample program, PRINTESC.CBL, is included with Microsoft COBOL Professional Development System version 4.0. 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 repeat the installation process with only the new component selected. The following is a code example:

   IDENTIFICATION DIVISION.
      PROGRAM-ID.  PRINTERCODE.
   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.
   000-MAIN-ROUTINE.
       OPEN OUTPUT PRINT-FILE.
       MOVE "THIS LINE IS NOT UNDERLINED" TO NAME-STREC.
       WRITE PRINT-REC FROM NAME-STREC AFTER ADVANCING 2.
  *This hex code underlines text for a HP LaserJet
  *The hex code is Esc&dD
       MOVE x"1B266444" TO UNDERLINE-REC.
       WRITE PRINT-REC FROM UNDERLINE-REC.
       MOVE "THIS LINE IS UNDERLINED" TO NAME-STREC.
       WRITE PRINT-REC FROM NAME-STREC AFTER ADVANCING 2.
  *This is the hex code that disables underlining of text.
  *The hex code is Esc&d@
       MOVE x"1B266440" TO UNDERLINE-REC.
       WRITE PRINT-REC FROM UNDERLINE-REC.
  *Esc E resets printer
       MOVE x"1B45" TO RESET-REC.
       WRITE PRINT-REC FROM RESET-REC.
       CLOSE PRINT-FILE.
   STOP RUN.

Additional reference words: 3.00 3.00a 4.00 Copyright Microsoft Corporation 1993.