Discussion Locked

Printing from VB

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

How do I print a file (txt AND rtf files are needed) from VB6 straight from code to the printer - I do not want to have to use the RTF Control - basically looking for code that does the same but with-out having to load the RTF control on a form.
I assume this can be done with the printer control but I cannot get it to work - or rather, I cannot figure out how to do it.
If the file is RTF, the graphics have to also be printed.

Can this be done via API. If I right click on a Rtf file I can click on print to execute a print right away, so something must be controling this, like the file type being linked to WordPad.
PS. I can only use DLLs, or whatever that come with VB6 or the OS.

9 replies

by maxwell edison

There's a third party developer who's addressed that issue. They say the following:

"The source code printer in Visual Basic is, to put it mildly, crude. It's definitely not something to write home about, or for that matter, show your manager or client. If source code is a deliverable or code walks and peer reviews are part of your regular routine, Code.Print Pro will make your code look good and save you time.

Code.Print Pro gives you full control over titles, margins, fonts and styles, line spacing, line numbering, headers/footers, and more. Create your own style for all your project documentation. Once you've defined your own settings, everything you print will look consistent and professional - the way you want it. Four-sided margin control assures you'll never again have to punch holes through your code when you place it in a binder. Adjustable line spacing and numbering make it easy to write notes between the lines during code."

-----------

A single user license isonly $99.

You can read the entire description and get download information at the following site:

http://www.hallogram.com/codeprnt/

(REMOVE SPACES from the pasted URL.)

Good luck,

Maxwell

by bbg

Thanks for the try but as I stated in my question I can only use DLLs, or whatever that come with VB6 or the OS. I do not want to have to buy additional software.
I am looking for a way to do this with what I already have. I am hoping that someone knows a way to do this in VB or call an Api function that either prints the rtf file or calls the default application that the rtf file is linked to and print it that way, (but with-out having to pull the application up on the screen).
Appreciate your try!

by bbg

Also VBA programmers: Does anyone know how to call the default application's print that a rtf file is linked to - with-out knowing what the default program is - possible using a built-in function? If I can see some ideas then maybe I can figure out what the call is doing and figure out how to convert this to Vb6 or call the same APi function.

by bbg

I only found code involving the use of the RTF control and this, as I mentioned above, is not what I wanted to do - "all" I want is a way to print a file (txt and rtf) directly. Thanks anyways!

by sl-campbell

In declarations section add:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long

Private Const SW_SHOWMINNOACTIVE = 7

Then create a public sub(or private depending on where the sub is called from - an rtf will usually be printed using Word/Wordperfect if installed but will at least use WordPad which is delivered with Windows and must also be installed if Word or another Word processor isn't):

Public Sub PrintTextFile_Sp(ByVal sFilePathAndName As String)
Dim lReturn As Long

'Will print the file using the applicationwhich is associated with that file name extension.

ShellExecute MEZ_000.hwnd, "Print", sFilePathAndName, ByVal 0&, ByVal 0&, SW_SHOWMINNOACTIVE

End Sub

You could change it to a function and use the return value of the API as the return value for the function in order to inform the caller if the print was successfull or not (successful= lReturn =0)
Load the API viewer add-in and check the constants that begin with SW_ to see what can be passed to the function and what the return errors are.

This discussion is closed to new replies.