Microsoft KB Archive/42361

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


"Bad File Name or Number" (Error 52) If CANCEL "LPT1: PROMPT"

Article ID: 42361

Article Last Modified on 11/21/2006

This article was previously published under Q42361

SUMMARY

OPENing the "LPT1:PROMPT" device name as #n in a program prompts you for various print options and printer paper sizes. If you click the CANCEL option, you will correctly receive the following error on a subsequent PRINT#n or WRITE#n statement:

"Bad File Name or Number" (Error 52)

This error occurs because you canceled opening the printer file. You can trap the error with an ON ERROR GOTO statement and then resume execution of the program.

This procedure applies to QuickBASIC Compiler Version 1.00, Microsoft BASIC Compiler Version 1.00, and Microsoft BASIC Interpreter Versions 2.00, 2.10, and 3.00 for Apple Macintosh.

MORE INFORMATION

The following is a code example:

ON ERROR GOTO ERHANDLE
OPEN "LPT1:PROMPT" FOR OUTPUT AS #1
' An error occurs on the following statement if you clicked CANCEL
' in the "LPT1:PROMPT" dialog box:
PRINT #1,"THIS IS MEANT TO GO TO PRINTER"
CLOSE
label1:
   PRINT "This is the end."
END
ERHANDLE:
   E = ERR  ' assign error number to variable E
   PRINT "ERROR NUMBER = "; E
   IF E = 52 THEN
     PRINT "YOU CLICKED THE CANCEL BUTTON. PRINTING IS CANCELED."
   END IF
   RESUME label1     ' Resumes execution at label1. File not opened.
                


Additional query words: BasicCom MQuickB

Keywords: KB42361