IgnatiusGo 08-24-2009, 01:49 AM I have read that to print one line at a time, I should use this:
Private Sub Command1_Click()
Open "LPT1:" For Output As #1
Print #1, "test message"
Print #1, vbFF
Close #1
End Sub
I tried it on a form with only one Command1. When I click it, nothing happen at all. why is that?
Gruff 08-24-2009, 02:15 AM You are trying to send to the printer as one would have under MS DOS. Windows is somewhat different when it comes to printers.
Try reading up on the 'Printer' Object in VB6 Help or Google 'VB6 Printer tutorial"
Here is a link (http://www.freevbcode.com/ShowCode.asp?ID=3646) to one of the first I googled.
IgnatiusGo 08-24-2009, 02:33 AM I know Printer.Print way of doing things, and I usually use it. However, that also means that I need to have everything finish before I enddoc it to print it. I want to print a line at a time, and continue again with on the same paper. I read two posts in this forum that suggest the above method. I just don't know why it does not work.
Gruff 08-24-2009, 02:42 AM Have you created a new Printer interface in Windows associating it with LPT1?
(This is an option when you create a new printer under printers and faxes.)
IgnatiusGo 08-24-2009, 03:06 AM OK, I do not exactly understand what you mean. If you ask whether I have installed printer in Windows XP with properties of Port LPT1 checked, then the answer is yes.
If I use printer.print in:
Private Sub Command1_Click()
Printer.Print
Printer.Print "Hello World"
Printer.EndDoc
End Sub
It works just fine
Cerian Knight 08-24-2009, 10:11 AM What kind of printer is this (e.g., Laser, Ink Jet, Dot Matix, etc.)? Or, in other words, is this particular printer known to support line-by-line printing? We do this with some of our part labels by printing to an old dot-matrix printer which supports line-by-line. In this case we print directly to 'LPT1:' without the printer needing to be installed under Windows. We do this for a different reason than you seem to want, but the effect is the same... putting characters on the paper before an EndDoc (or FF) is requested. This just won't work with some printers, though.
To further clarify: this kind of functionality is only available (to my knowledge) on tractor-feed line-printers. We used device specific codes to accomplish this (for other reasons), but that is not required.
IgnatiusGo 08-24-2009, 03:51 PM Hmm, thanks everyone. I have got it work by simply remove ":" from "LPT1:" to "LPT1". I do not understand why my printer is different from other examples in this forum, but it works. I guess, that means my printer support line-by-line printing too.
Cerian Knight 08-24-2009, 05:03 PM Waiting till you have everything you need before sending the .EndDoc should have the same effect. My discussion was more related to seeing the initial printed output on paper before you are done creating the rest of the page. But, I take it that is not what you were after... or if it is, then you are certainly not using a laser printer (or most ink jets I'm familiar with, for that matter).
IgnatiusGo 08-24-2009, 08:54 PM Well, I need to print one line each time without ejecting the whole page. Then, when a new event comes up, print another line below it, and so on... So, one line each event, on the same page, again and again. So, I can't wait for it to fill the whole page and use enddoc, as it must be seen in the printer on each event.
|