To access the printer port, one must first install
the free .dll by Prof. Anjan, a college professor in
India. It's calleed, vbio.dll.
To find his page, do a google.com search!
Assuming that you have a printer driver set up on your machine you can check its port by Printer.Port. This checks the default printer of the machine that the program is running on. If this then equals what you want(in debug ?Printer.Port) then you can use one of my other suggestions in the other thread that you posted thread222-397861. If you need to change the printer that you print to search this forum for "SetDefaultPrinter API" using all words.
However if you do not want to set the default printer to another printer but you do want to use the printer object to print your text file to the printer then you could use some code like this to find a printer driver that is set to LPT1:...
[tt]
Dim P As Printer
For Each P In Printers
If P.Port = "LPT1:" Then
Set Printer = P
Debug.Print Printer.DeviceName
Exit For
End If
Next
[/tt]
This loops through all of the printer drivers installed on the system looking for a printer whose port is "LPT1:" and sets the applications printer object to that driver (added a debug to find its name in design).
So let us assume that via the code above you have found a printer that is connected to LPT1:. You could then use the richtextbox to print your text file like so...
But, you really do not need to do that considering that you have set the application to what printer you want to use. You could use a regular text box to accomplish what you want also...
And, for the sake of arguement, lets say you do not want to display/load the text from a file into a textbox/richtextbox you could then use...
[tt]
Dim FNumb As Integer, FName As String, TextLine As String
FName = "Your path to text file"
FNumb = FreeFile
Open FName For Input As #FNumb
Do While Not EOF(FNumb)
Line Input #FNumb, TextLine
Printer.Print TextLine
Loop
Close #FNumb
Printer.EndDoc
[/tt]
but of course the code above would not take into consideration the length of the line of text and you could lose some data on the output, and if that is a concern then I would suggest that you use the richtextbox for your output as shown above.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.