Copying to an LPT port in Visual Basic 5.0

What is the best way to copy a file to an LPT port that will work in both Windows 95 and Windows NT. I have an old program that I wrote in Quick Basic that I use to copy plotfiles generated in AutoCAD to a local or network LPT port (i.e. LPT1 LPT2 LPT3)

Here a line from the Quick Basic program that I wish to duplicate in VB5

SHELL "COPY " + PLOTNAME$ + " LPT1:"
ToZaResQAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cymbolicCommented:
The shell command still works in VB5.  SO you can shell to your hearts content.  The only difference is that it is asynchronous, so it starts another task while your shelling program continues to run.
0
cymbolicCommented:
Also, just as a side comment, you can start a windows program using the Shell command or a batch command, or other in a DOS window in 95, and windows will start asynchronously the windows program you requested, while your DOS window continues to run.
0
cymbolicCommented:
One more thing.  Under windows you need to "capture" the port  on your designated printer setup in order to "catch" these files for network printing.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

ToZaResQAuthor Commented:
I know the shell command still works in VB5. But I keep getting error 53 when I try to copy to an LPT port.

When I use the same format from above it also doesn't work
SHELL "COPY " + PLOTNAME$ + " LPT1:"

Could you please provide an example of how to copy a file to an LPT port in VB5

I know this is the format for the command in VB5 but I have been able to figure out how to format the line so I can copy to an LPT port

Shell(pathname[,windowstyle])


Remmember it must work in win95 and NT
0
cymbolicCommented:
If you just try to shell "Copy" you will get a file not found.  Make a batch file that issues your copy or type command, then sehll the batch file with the name for the file you want printed.

batch file:
copy %1 Lpt1

Shell "mybat.bat "+plotname$
0
ToZaResQAuthor Commented:
Seems a little strange that I have to shell out and run a batch file just to do this simple task.. Is there no better way built into Visual Basic 5.0 for copying a file to an LPT port?

Also. I've tried opening an LPT port for binary output but that only works in Win95.. I can't believe there is not a better way to do this.
0
cymbolicCommented:
Note the following syntax also:
copy /b filename lpt1:

The switch /b directs the system to print a binary file.

Also,
Windows-based applications and MS-DOS-based applications print in different ways and follow different rules. Windows-based applications send print jobs to printers added in the Printers folder. They typically use the printer drivers associated with those printers. However, some high-end desktop publishing or CAD applications have their own internal program copy of printer drivers.
In contrast, MS-DOS-based applications are unaware of the printers added in the Printers folder. They print to ports instead of to printers. This can cause problems. Whereas you could add several dozen printers in the Printers folder, most MS-DOS-based applications are limited to ports like LPT1–LPT3 and COM1–COM2. Windows NT accommodates MS-DOS-based applications in the following ways:
·      If the port is controlled by the network redirector (for example, when a net use command redirects output to a shared resource), the redirector determines where the job goes.
·      If the port is not controlled by a network redirector, but a printer prints to that port, the job is submitted to that printer, and that printer’s spooling options take effect.
·      If the port is not controlled by a network redirector, and no printer prints to that port, the job goes directly to the port device driver and prints (presuming, of course, that a print device is connected to that port).
 
Also, here's a real hoot! The microsoft developers network (you know, that really technical support product from Microsoft) gives the following instructions to fix it's own printing problems:

If you print technical articles, such as the Microsoft Journal articles, from MSDN disc #4, only the first 5-10 pages may print. You will not receive any error messages or other indications.
The number of pages printed varies from printer driver to printer driver.

WORKAROUND

1. Open Control Panel and choose the Printer icon.

2. Select Connection and set the default printer to File. When
   you print an article in MSDN you will be prompted for a filename.

4. After you've printed from MSDN, run MS-DOS Command Prompt and copy
   the file to the printer port. For example, type the following to copy
   myfile.prn to the printer port lpt1

      copy <myfile.prn> <lpt1>:

   where <myfile.prn> is the file listed in the dialog box that appeared
   during your printout and <lpt1>: is the port connected to your printer.




0
mrmickCommented:
hmmm...

ToZaResQ, please reject cymbolic's answer and give me credit for this one because the following is exactly what you're looking for.

shell "command.com /c copy c:\YourFile.txt lpt1:"

This works for NT as well as 95.

If this doesn't work on the NT machine, click start, settings, right click the printer and select properties.  Make sure print spooling is enabled and make sure the LPT1 port is selected as an available port.

If this doesn't work on the 95 machine, click start, settings, right click the printer and select properties.  Under the details tab, make sure the capture port is set to LPT1.

0
mrmickCommented:
If you want a windows based solution to this issue, check out in the Microsoft Knowledge Base:

Article ID: Q154078
Title: "HOWTO: SendRaw Data to a Printer Using the Win32 API from VB"
http://premium.microsoft.com/support/kb/articles/q154/0/78.asp

0
ToZaResQAuthor Commented:
Thanks mrmick you're right on the money!!

Thanks!!
0
ToZaResQAuthor Commented:
Regrab this question so I can give you credit
0
mrmickCommented:
Thanks

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.