:-:- Print in DOS-TEXT Mode :-:-

Dear Experts,

How can I print the text of a
RichTextBox in DOS-TEXT mode (not a graphical mode)
through a Dot-Matrix Printer
without given any printer settings.

Who is Participating?
TimCotteeConnect With a Mentor Commented:
Why not try this:

Open "LPT1" For Output As #1
Print #1,RichTextBox1.Text
Close #1
You only want the TEXT of a RichTextBox?

TXT = RichTextBox1.Text
printer.print txt

If you wanted the rich text version you would use something like this. But printing rich text is a different story.

RTXT = RichTextBox1.TextRTF
' Ptext as text box  
  Printer.Print Chr(13) & Chr(13) & Chr(13)
  Printer.FontBold = False
  Printer.FontSize = 10
  Printer.Print Space(5) & Ptext
  Printer.EndDoc  ' Print done.
' I try this, it can print in any default printer
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

serco, you have been here for 5 years, never asked nor answered a single question yet you have the 100% guaranteed answer that doesn't even refer to the actual control in use? Impressive. Please refer to the guidelines on comments vs answers at the bottom of this page. If you continue to post answers your account will be referred to customer services for possible penalty.


Indeed serco got it almost exactly right, though without discussing the RTB control it is not quite there.

The Rich TextBox Control has two properties, the .TextRTF and the .Text property, the former includes all of the RTF control characters and the formatting codes for the display of the text in the RTB. The latter is purely the plain text without any control codes. If you use this property you can output it to any printer either using the printer object or using any direct methods (api or other) to open and print to a printer.
eesrinivaassanAuthor Commented:
Please kindly understand
I am not asking to just print the contents.
I want to print the RichTextBox Contents
through Dot-Matrix printer in
(The Printed letter quality should be
just like the printing taken through
the following DOS command
c:\>dir >prn )

Now What I am doing is to accomplish the above,
I am first saving the contents of RichTexBox in
a file.  Then I am sending the contents of the
above file to printer through a batch file
contains the following line
copy <filename.txt> /b lpt1
I am running the batch file through SHELL command.

It works fine.

I want to know, is there any better Idea than the
Q175083 - HOWTO: Print Line-by-Line to a Printer
Question, why are you side stepping the windows driver?

If you simply want to dump text then the answer given by TimCottee should work fine. On the other hand. If you try to send special printer commands you will need to fully understand the printer you are sending to and be aware that changing printers could break your program.

It is posible to set up any printer to be a DOS printer which may be helpful.  I am just trying to fully understand why you are trying to print in the way you are instead of using the windows drivers.
I think it is for speed.....correct, eesrineevaasan?
The above TimCottee answer should do it, but I think the LPT1 needs a colon (:) after it.

Another way to do it, which actually used DOS is this:

Private Sub PrintRTB()
  const cTempFile as string = "C:\Temp\RTBText.txt"

  open cTempFile for output as #1
  print #1, RichTextbox1.Text
  Close #1
  Shell ("Command /c Copy " & cTempFile & " LPT1:")
  kill cTempFile
end sub
I too had put up a similar question sometime back. I was given 2 suggestions which unfortunately i could not completely try out (because i also wanted to change the size of font to big, bold . . .).

One was what TimCottee said

Open "LPT1" For Output As #1
Print #1,RichTextBox1.Text
Close #1

The other one is using the Escape API function
But i am not sure whether they will work for Windows NT also.


The reason (most probably) why eesreenivaassan wants to directly print to the dot matrix printer via dos mode is that most of the automated work in India is in foxpro and printing via foxpro is fast. Windows printing is slow and end users who are moving to a visual interface like vb want the same speed and economy while printing.
Hi eesrinivaassan,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept TimCottee's comment(s) as an answer.

eesrinivaassan, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

E-E Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.