Solved

Printing in VB4 using DOS's print

Posted on 1998-11-17
4
206 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 77
vb6 programatically bring window to front 8 65
SSRS expression Issue finding a string 10 66
Copy a row 12 59
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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 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

21 Experts available now in Live!

Get 1:1 Help Now