Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error while printing a Text File

Status
Not open for further replies.

sduraiappa

Programmer
Mar 5, 2004
54
0
0
IN
I am trying to print a text file to a Dot Matrix Printer.

I use the following statement:

A1 = Shell("C:\WINDOWS\DOSPRNT.BAT " & TEMPFILE, vbMinimizedNoFocus)

Dosprnt.bat has the following lines:
TYPE %1 > PRN

While trying this i got a error message in the MsDos window.
"File Creation Error"

Please tell me what is the reason for the error ?

Regards,

Duraiappan.
 
Does the variable TEMPFILE contain the path to the file? ... the file's extension?
 
Try this in your .BAT file:

Code:
copy  %1  PRN:

Note the colon after PRN

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
The parameter (TEMPFILE) is correct. I have verified it in debug mode. And when i try the same batch file in Command Prompt, it works fine. When i call it from Shell() i got the error message "File creation error".

Any help.

Duraiappan
 
I suspect the redirection isn't working when you submit it through the shell command. It seems like it's trying to create a file. Add : as specified above or try the copy command. Let us know if neither of those methods work.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
I tried by replacing prn with PRN: But i get the same error message.

Any other help.

Duraiappan
 
Since all else has failed, how about trying
Code:
PRINT LPT1 %1
 
It has been a while since I have played with dos, HOWEVER:

I think if you use a single PERCENT sign it works at the command prompt.

BUT, in a batch file you need to use TWO Percent Signs.

Try to in the batch file and advise us if this helps.
 
I tried PRINT LPT1 %1, i got bad command name error message.

I use two % signs and i got bad file name error message.

Mean while, i found the DOSPRNT.BAT works fine in some system and i dont work in some systems. When i change the printer port type as ECP in bios it works fine. But in some system when i set the port type as ECP it doesnot work.

Still i dont find any reason for the error.

Duraiappan
 
Try using notepad to print it (the default printer will be used). The command string is: [green]C:\WINDOWS\system32\NOTEPAD.EXE /p <file name goes here>[/green]. Note: it may be located in a differnt folder on your machine. Most likely it's in the path, so you should be able to get by with just the program name.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
I Cannot use notepad to print, as i use control characters for dot matrix printer in my text file. So i have to print the file through dos mode only. So only i am using this Batch file to print the text file.

Duraiappan.
 
Try adding this to the beginning of the run string:
Code:
cmd /c
I found I couldn't get redirection to work out of the shell without it.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
I am working in Windows 98. I dont find cmd /c will help me.

Duraiappan
 
Hi to All,

Atlast i found a solution for my problem. I use the following code:

Dim tline As String
fnum = 1: ofnum = 2
Open TEMPFILE For Input As #fnum
Open TPRNPORT For Output As #ofnum
Do While Not EOF(fnum)
Line Input #fnum, tline
Print #ofnum, tline
Loop
Close #fnum
Close #ofnum

It works fine now.

Thanks to everyone.

Duraiappan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top