On-Line Printing

I am creating a program with an on-line printing feature.  It is a logging system which prints every new entry log directly to the printer.

My problem is how to do it since VB6 does not seem to support this feature.
And whenever I use the EndDoc command, the printer will start with a
new page.  How to go about this?

I have attached an example below:


Private Sub Form_Load()
   Timer1.Interval = 1000   ' Set Timer interval.
End Sub

Private Sub Timer1_Timer()
 Label1.Caption = Time   ' Update time display.
 Printer.Print Time
 'Printer.EndDoc
 
End Sub
rcbarotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cvidlerCommented:
You can't use the enddoc command (it will always start a new page), and the printer won't start printing (because vb doesn't send the data to Windows) until you do.

I don't think you can do this, unless you print directly to the printer port, using some sort of port I/O control.
0
rcbarotAuthor Commented:
Adjusted points to 100
0
adityauCommented:
The following code should work. Call the sub PrintLine with the string which u want to print as a parameter whenever u want to print.

Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

Private Type DOCINFO
    pDocName As String
    pOutputFile As String
    pDatatype As String
End Type

Private Sub PrintLine(ByVal strPrintString As String)
    Dim lngPrinter As Long
    Dim lngReturn As Long
    Dim lngDoc As Long
    Dim udtDocInfo As DOCINFO
    Dim lngWritten As Long

    lngReturn = OpenPrinter(Printer.DeviceName, lngPrinter, 0)
    If lngReturn = 0 Then
        MsgBox "The Printer is not recognized"
        Exit Sub
    End If
    udtDocInfo.pDocName = "rcbarot"
    udtDocInfo.pOutputFile = "rcbarot"
    udtDocInfo.pDatatype = vbNullString
    lngDoc = StartDocPrinter(lngPrinter, 1, udtDocInfo)
    Call StartPagePrinter(lngPrinter)
    lngReturn = WritePrinter(lngPrinter, ByVal strPrintString, Len(strPrintString), lngWritten)
    lngReturn = EndPagePrinter(lngPrinter)
    lngReturn = EndDocPrinter(lngPrinter)
    lngReturn = ClosePrinter(lngPrinter)
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rcbarotAuthor Commented:
I am accepting this answer but is there any other way?  I am quite new in VB Programming.  

Thanks.
0
rcbarotAuthor Commented:
adityau,

I have tried using the program you had given but it doesn't seem to work.  I have tried several printers, dot matrix, deskject but couldn't get it to work.  I have tested with the program below.  What am I missing?


_______________________________________
'The following code should work. Call the sub PrintLine with the string which u want to print as a parameter whenever u want to print.

Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

Private Type DOCINFO
    pDocName As String
    pOutputFile As String
    pDatatype As String
End Type


Private Sub PrintLine(ByVal strPrintString As String)
    Dim lngPrinter As Long
    Dim lngReturn As Long
    Dim lngDoc As Long
    Dim udtDocInfo As DOCINFO
    Dim lngWritten As Long

    lngReturn = OpenPrinter(Printer.DeviceName, lngPrinter, 0)
    If lngReturn = 0 Then
        MsgBox "The Printer is not recognized"
        Exit Sub
    End If

    udtDocInfo.pDocName = "rcbarot"
    udtDocInfo.pOutputFile = "rcbarot"
    udtDocInfo.pDatatype = vbNullString
    lngDoc = StartDocPrinter(lngPrinter, 1, udtDocInfo)
    Call StartPagePrinter(lngPrinter)
    lngReturn = WritePrinter(lngPrinter, ByVal strPrintString, Len(strPrintString), lngWritten)
    lngReturn = EndPagePrinter(lngPrinter)
    lngReturn = EndDocPrinter(lngPrinter)
    lngReturn = ClosePrinter(lngPrinter)
End Sub


Private Sub Form_Load()
   Timer1.Interval = 1000   ' Set Timer interval.

End Sub

Private Sub Timer1_Timer()
    Label1.Caption = Time   ' Update time display.
   
    'Printer.Print Time
    PrintLine Time
   
   
End Sub

0
adityauCommented:
I am sorry. There is some problem. Use the following statement where u have used
udtDocInfo.pOutputFile = "rcbarot" . It should be

udtDocInfo.pOutputFile=vbNullString.

It should work.
0
adityauCommented:
I am sorry. There is some problem. Use the following statement where u have used
udtDocInfo.pOutputFile = "rcbarot" . It should be

udtDocInfo.pOutputFile=vbNullString.

It should work.
0
rcbarotAuthor Commented:
Thanks a lot pal!  I tried your corrections and worked pefectly fine.  Thanks a lot for the help.
0
adityauCommented:
u r most welcome boss
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.