Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone tell me how to use the win API to print a file

Status
Not open for further replies.

NeilBarnard

Programmer
Nov 10, 2000
6
IN
Hi guys,

here's my problem, I dont want to use crystal reports for reporting, neither is the VB data report my prefered option. I was thinking more on the lines of creating a text report file and then sending it to the printer. PLEASE NOTE THAT THE PRINTER IS DOT MATRIX. Can anyone tell me how to use the windows API to print a text file directly.

Any other suggestions are welcome
Thanx
 
'Insert the following code to your form:

Private Sub Form_Load()
On Error Resume Next
'Replace 'c:\windows\win.ini' with the name of the file you want to print.
Printer.Print "c:\windows\win.ini"
Printer.EndDoc
End Sub

Eric


Eric De Decker
vbg.be@vbgroup.nl
 
Gee, It would be nice if it were that easy. All that printed was c:\windows\win.ini at the top of the page.
You need to open the file for inpu and illiterate through and printing each line.

Private Sub Command1_Click()
Dim str As String
Open "c:\windows\win.ini" For Input As #1
While Not EOF(1)
Line Input #1, str
Printer.Print str
Wend
close #1
Printer.EndDoc
End Sub


And as far as your text printer, You can set your printer up to just print text. Go to 'Add New Printer' and select 'Generic'.

David Paulson


 
David,

There's one problem with that approach: Printer.Print str will try to print a paragraph on a single line, so the first line prints and the rest disappears off the right side of the paper (at least when I do it).

Maybe there's something obvious that I'm missing, but having word wrap turned on for a text box doesn't mean that word wrap is turned on when you send the text to the printer!

Any (reasonably simple) suggestions for a workaround for this problem (other than putting a vbCrLf at the end of each line, which only works if the text box and the printing area on the paper are the same size)?

Thanks in advance for your thoughts on this, since I'm trying to write my own VB improved version of Microsoft Notepad and everything's falling nicely into place except for the File->Print routine, which has turned out to be surprisingly complex (and more complicated than I really want to deal with at this point).

Regards,

Barry Traver
 
This doesn't use the API but it might be what you are looking for
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top