Solved

Copying to an LPT port in Visual Basic 5.0

Posted on 1997-12-26
12
585 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ToZaResQ
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks mrmick you're right on the money!!

Thanks!!
0
 

Author Comment

by:ToZaResQ
Comment Utility
Regrab this question so I can give you credit
0
 
LVL 8

Accepted Solution

by:
mrmick earned 100 total points
Comment Utility
Thanks

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now