Solved

Printing in VB4 using DOS's print

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

17 Experts available now in Live!

Get 1:1 Help Now