Solved

Printing in VB4 using DOS's print

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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