Question Locked

printing a text file in VB6

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi
I have a text file created from within VB. I need to print it. I have been using DOS command till now "shell(type filename > prn)" but that was to printer connected at LPT. Now it is laser printer connected at USB or COMM port.
I am a beginner....

Thanks

VKV

9 replies

by p.j.hutchison

To print from dos to a non-LPT printer, you need to:
1. Share the printer using the Print and Faxes control panel
2. Open a command prompt
3. Type NET USE LPT1 \\computername\printershare
or some other LPT port.

4. Now print as normal e.g. TYPE >LPT1: myfile

5. Alternatively you could create a RichTextBox in VB and use one of its methods to print the text in the RTB.

by vrinda

thanx...
But i guess i cud not explain properly...

I need to print from within VB.
Can u give some command or something to start with? How to print text from RTB?

Thanx

by zionsoft

pls use a richtext box and use following code

richtextbox1.load("c:\test.txt")
RichTextBox1.SelPrint(Printer.hDC)

Happyy.. coding....!

By : Lenin Paily - Zionsoft

by mirko.klotz

In VB6 there's a global printer object, called "Printer". You can write (using "Print") and paint (using numerous methods like "Line" or "Circle") on it very similar to the PictureBox object. The method "EndDoc" sends your stuff to the current printer.
There's also a collection named "Printers" containing all installed printers. You can use it to select where you want to print.

Mirko

by robaaaaaa2

As someone else said, use the printer object in VB.
In simple terms:

printer.print MyTextBox.Text

printer.enddoc

There are a lot of other properties and methods you can play with.

by vrinda

Thanx for the suggestion. But I need to change font size in between... some normal font size, some condensed font.... How do I do this from inside VB?

Vrinda

by p.j.hutchison

If you use a RichTextBox you can specify fonts and so on.

Alternatively, you can send the printer commands for your printer. ESC/P commands for Epson, PCL commands for HP Printer etc.

by aikimark

Shell "notepad.exe /P ""C:\TR\How To Print File From VB.txt""", vbNormalFocus

This discussion is closed to new replies.