QBasic LPRINT Uses Only LPT1 (81167)



The information in this article applies to:

  • Microsoft MS-DOS operating system 5.0
  • Microsoft MS-DOS operating system 5.0a
  • Microsoft MS-DOS operating system 6.0
  • Microsoft MS-DOS operating system 6.2
  • Microsoft MS-DOS operating system 6.21
  • Microsoft MS-DOS operating system 6.22

This article was previously published under Q81167

SUMMARY

The LPRINT command in QBasic expects a printer to be connected to the LPT1(PRN) port. If a printer is not connected to LPT1 and LPRINT is used, QBasic displays a "Device fault" error message.

MORE INFORMATION

To use the LPRINT command when a printer is connected to a port other than LPT1, do the following:
  • If the printer is connected to a COM port, the MS-DOS MODE command can be used to redirect printing from LPT1 to COMx.

    For example, to redirect to COM1, use the following command:

    MODE LPT1=COM1

    If you need to cancel the redirection when finished, use the following command:

    MODE LPT1

  • MS-DOS allows you to treat all devices as if they were files. Use the QBasic OPEN command to open a port as a file and then print to the port.

    Sample QBasic code to print using LPT2:

    OPEN "LPT2:" for random as #1

    PRINT #1, "Text to be printed"

    -or-

    WRITE #1, Text to be printed

    CLOSE #1

The QBasic WRITE command does not need quotation marks surrounding the text to print; however, PRINT does. The CLOSE command writes the data out to a file (the printer). The CLOSE command should only be used after all PRINT or WRITE commands are executed.

Modification Type:MajorLast Reviewed:5/12/2003
Keywords:KB81167