?
Solved

Printing in VB4 using DOS's print

Posted on 1998-11-17
4
Medium Priority
?
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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