Solved

Copying to an LPT port in Visual Basic 5.0

Posted on 1997-12-26
12
593 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to With line 4 63
MS Access 03, TransferText, decimal places 8 78
converting visio 2010 to powerpoint 2010  - formatting issues 5 92
Problem to line 23 53
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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