Hi Nagendra,
Here is some code which I got from a previous post on this list. I've
adapted it a tad bit and I used it successfully in a recent project of mi
ne.
It prints beatifully on the oldest of line printers.
Just a note - I haven't tested it on inkjet or laser printers yet.
'Code Start-----------------
'Put this in a general module
Public Type DocInfo
=20 pDocName As String
=20 pOutPutFile As String
=20 pDataType As String
End Type
Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
=20 hPrinter As Long) As Long
Public Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
=20 hPrinter As Long) As Long
Public Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
=20 hPrinter As Long) As Long
Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
=20 "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long
, _
=20 ByVal pDefault As Long) As Long
Public Declare Function StartDocPrinter Lib "winspool.drv" Alias _
=20 "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long
, _
=20 pDocInfo As DocInfo) As Long
Public Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
=20 hPrinter As Long) As Long
Public Declare Function WritePrinter Lib "winspool.drv" (ByVal _
=20 hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
=20 pcWritten As Long) As Long
'This I call before printing
Public Sub SetLPrinter()
=20 Dim MyDoc As DocInfo
=20 Dim lReturn As Long
=20 Dim lDoc As Long
=20
=20 lReturn =3D OpenPrinter(Printer.DeviceName, lhPrinter, 0)
=20
=20 MyDoc.pDocName =3D "Test1"
=20 MyDoc.pOutPutFile =3D vbNullString
=20 MyDoc.pDataType =3D vbNullString
=20
=20 lDoc =3D StartDocPrinter(lhPrinter, 1, MyDoc)
=20 Call StartPagePrinter(lhPrinter)
End Sub
'This I call to clean up after printing
Public Sub KillLPrinter()
=20 Dim lRet As Long
=20
=20 lRet =3D EndPagePrinter(lhPrinter)
=20 lRet =3D EndDocPrinter(lhPrinter)
=20 lRet =3D ClosePrinter(lhPrinter)
=20
End Sub
'This I set somewhere globally
Public lhPrinter As Long
'A typical procedure to do some printing
Private sub PrintStuff()
=20 Dim lReturn As Long
=20 Dim lRet As Long
=20 Dim PrintStr As String
=20 Dim lpcWritten As Long
=20
=20 SetLPrinter
=20
=20 PrintStr =3D "This is line one" & vbCrLf _
=20 & "This is line two" & vbCrLf
=20 lReturn =3D WritePrinter(lhPrinter, ByVal PrintStr, Len(PrintStr),
lpcWritten)
=20 KillLPrinter
End Sub
'Code End --------------------
Kind regards,
Brad.
-----Original Message-----
From: Nagendra Kumar K [mailto:knagendrak@h...]
Sent: Friday, October 18, 2002 5:07 PM
To: professional vb
Subject: [pro_vb] DOS Printing
Hello Everybody,
Can any body help in printing from VB.
I have two options
1.DOS Printing
2.Windows Printing
B'coz DOS printing is more fast than Windows Printing and time saving als
o.
Any body Please help how to do these from VB.
Thanks i advance
Regards
NAgendra K.
_________________________________________________________________
Unlimited Internet access for only $21.95/month.=A0 Try MSN!
http://resourcecenter.msn.com/access/plans/2monthsfree.asp
---
Visual C# - A Guide for VB6 Developers
This book will make it easy to transfer your skills
from Visual Basic 6 to C#, the language of choice
of the .NET Framework.
http://www.wrox.com/ACON11.asp?ISBN=3D1861007175&p2p0059
DISCLAIMER : Volkswagen of South Africa (Pty) Ltd
=20
Any views expressed in this message are those of the individual sender.
No liability shall attach whatsoever to VWSA from this communication exce
pt
where the sender is acting on specific authority of VWSA, such authority
being public record and acknowledged by VWSA by nature of the employee's
functions. This document may in no way be photocopied, printed, scanned o
r
electronically duplicated for any purposes other than that for which it w
as originally
intended.
If you are not the intended recipient of this communication, please disca
rd
this message and notify VWSA immediately at postmaster@v...