Solved

Printing in VB4 using DOS's print

Posted on 1998-11-17
4
208 Views
Last Modified: 2011-09-20
Hi,
  I am trying to print a textfile from VB4 , not using printer object but using
Shell("print.exe filename"), vbNormalFocus
this raises a problem cause it will ask for the PRN object in a DOS window while I don't want any user interaction so I used:
Shell("copy filename PRN"), vb..
This does not work! I typed it in DOS command line and it works perfectly.. (PRN is the deafult printer)
So I did :
Shell ("prt.bat filename"),vb..
where prt.bat is a BATCH file containing:
copy %1 PRN
It works!

My question is:
Why must I create a batch file to run the command to print to the printer? How can I directly (Shell) print a textfile to the printer or perhaps use copy directly?

Thanks!!
0
Comment
Question by:Haho2
4 Comments
 
LVL 3

Expert Comment

by:vikiing
ID: 1445334
Change COPY command to be read as:

       COPY/B  filename  LPT1

("/B" switch lets you print not only text but graphics data, which otherwise would be garbled each time a control-char [ASCII < 32] is detected by COPY command).
0
 

Author Comment

by:Haho2
ID: 1445335
Thanks vikiing.
it still doesn't solve the problem as I have to include it in a batch file and then "shell" the batch file.
Besides, graphics isn't important as it is always 100% text.
How can I print directly from the "shell" command using copy, print, whatever...whithout a batch file and any user interaction to the default printer?

and also I noticed a funny problem, if I print sequentially a few files, the first dos window (for the first file) is not closed while the rest executes ok, and then closes (finishes). Why is the first window always not closed.. when I click on the window, it executes (the print) and then closes...

Thanks !!!

0
 
LVL 14

Expert Comment

by:Matti
ID: 1445336
Why don't try diferent way keep the bat file but
make temporary whit the main program.
It is quite easy to write a bat file on disk then exequte it
and kill it.

This is not bossible usin VB shell function you need to
ceate complex API call secuence and If you are using 16bit Vb4
this is not possible ShellExequte function will allow more.
0
 

Accepted Solution

by:
cameron2 earned 50 total points
ID: 1445337
Hello!

This code is to print a picturebox you can use this for anything textboxes.

    Printer.Print Text1.Text
    Printer.EndDoc
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Restricting text box entry from \/:?<>"| 9 86
Best way to parse out a json string in VB6? 10 163
Problem to With line 4 57
VB6 - Scroll Mouse wheel on Picturebox 13 42
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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

786 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