Microsoft KB Archive/42361

= &quot;Bad File Name or Number&quot; (Error 52) If CANCEL &quot;LPT1: PROMPT&quot; =

Article ID: 42361

Article Last Modified on 11/21/2006



This article was previously published under Q42361



SUMMARY
OPENing the &quot;LPT1:PROMPT&quot; 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:

&quot;Bad File Name or Number&quot; (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 &quot;LPT1:PROMPT&quot; FOR OUTPUT AS #1 ' An error occurs on the following statement if you clicked CANCEL ' in the &quot;LPT1:PROMPT&quot; dialog box: PRINT #1,&quot;THIS IS MEANT TO GO TO PRINTER&quot; CLOSE label1: PRINT &quot;This is the end.&quot; END ERHANDLE: E = ERR ' assign error number to variable E   PRINT &quot;ERROR NUMBER = &quot;; E   IF E = 52 THEN PRINT &quot;YOU CLICKED THE CANCEL BUTTON. PRINTING IS CANCELED.&quot; END IF  RESUME label1     ' Resumes execution at label1. File not opened.

Additional query words: BasicCom MQuickB

Keywords: KB42361

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.