Solved

Copying to an LPT port in Visual Basic 5.0

Posted on 1997-12-26
12
596 Views
Last Modified: 2013-11-25
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:"
0
Comment
Question by:ToZaResQ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1447508
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
 
LVL 9

Expert Comment

by:cymbolic
ID: 1447509
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
 
LVL 9

Expert Comment

by:cymbolic
ID: 1447510
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:ToZaResQ
ID: 1447511
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
 
LVL 9

Expert Comment

by:cymbolic
ID: 1447512
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
 

Author Comment

by:ToZaResQ
ID: 1447513
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
 
LVL 9

Expert Comment

by:cymbolic
ID: 1447514
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
 
LVL 8

Expert Comment

by:mrmick
ID: 1447515
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
 
LVL 8

Expert Comment

by:mrmick
ID: 1447516
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
 

Author Comment

by:ToZaResQ
ID: 1447517
Thanks mrmick you're right on the money!!

Thanks!!
0
 

Author Comment

by:ToZaResQ
ID: 1447518
Regrab this question so I can give you credit
0
 
LVL 8

Accepted Solution

by:
mrmick earned 100 total points
ID: 1447519
Thanks

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question