Link to home
Start Free TrialLog in
Avatar of EYoung
EYoungFlag for United States of America

asked on

Open (printer) for output???

I have written a small vb6 program that writes to a special label printer that is directly connected to the user's parralel port "Lpt1".  The program works just fine as follows:

Open "Lpt1" for Output as 1
Print #1, "Print line 1"
Print #1, "Print line 2"
Close #1

Now, however, the user is now asking to move the label printer to the network's file server so anyone can print to it.  How do I change the Open command line to point to the Windows default printer instead of Lpt1?

Thanks for the help.
Avatar of RanjeetRain
RanjeetRain

Several steps.

1. Install the printer on the file server and share it
2. Come back to the client and install the printer
3. Check the printer properties and see what "port" is it connected to
4. Try printing to that port

If it is possible you will be successful. Othewise, leave behind this quick and dirty method and print using the standard windows method. That method will offer you many advantages, such as, spooling, backgroud printing, buffering etc etc.

I think you need some kind of Printer Setting in your software.

The above post is what needs to be done on the networked computers. What is required further is at the software part. A few senarios might make thing a bit of a mess:

[1] A user at a client removed the printer
[2] A user at a client changed the default printer
[3] A user at a client decided to change the printer name (god knows why..)

Create a Setting file to record the Printer Name. Can be done in a simple text file. Then when the program loads up you could set the printer. It may look something similar to this:

Private Sub SetPrinters(PrinterName As String)

    For Each x In Printers
        If UCase$(Trim$(x.DeviceName)) = UCase$(Trim$(PrinterType)) Then
            Set Printer = x
            Exit Sub
        End If
    Next
   
    MsgBox "Printer (" & PrinterType & ") specified in System Settings could not be found." & Chr$(10) & Chr$(10) & "Please reset the Printers at System Settings.", vbCritical, "System Settings Anomaly - Printer"

End Sub

i dint know u cud print to lpt1.

in that case u shud be able to do:

Open "PRN" for Output as 1 'after setting the default printer.
i dont think u'll have to specify the default printer here...

just use print command
Normally, if there are only one printer available, there is no need to set printer.

Assuming nothing will stay constant in an office environment, i think it is important to code according to the user's environment rather than our preconceived ideas of how they may operate.

You could list all the Printers available with these codes. You need:
[1] a ComboBox (cbo_ReportPrinter) set style to 2-Dropdown List
[2] a Command Button

Private Sub Command1_Click()
Dim XPrinter As Printer

    cbo_ReportPrinter.Clear
    For Each XPrinter In Printers
        cbo_ReportPrinter.AddItem (XPrinter.DeviceName)
    Next
    If cbo_ReportPrinter.Enabled = True Then cbo_ReportPrinter.SetFocus
End Sub
Avatar of EYoung

ASKER

RanjeetRain - I did that and it did not work.  Additionally, each computer could use a separate port.  Also, on a network you do not use ports off the local computer to direct the output to a printer.

Jenn3 - I did not follow what you are saying.  Even if I get the name of the printer, how do I use it in the open and print commands.  I already have tried substituting the network printer name and that does not work.

agj - Tried PRN and that does not work.  Good idea though.

anv - I tried not specifing the printer and just printing, but nothing happened.  Did not get an error, just nothing came out on the printer.

ajaypappan - Tried the like suggestion but did not work.

Any other ideas?  I suspect the answer is really simple, just elusive.  Thanks for the input.  Please keep the suggestions coming.
ASKER CERTIFIED SOLUTION
Avatar of Jenn3
Jenn3
Flag of Åland Islands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I mean.. i misunderstood what you have coded earlier.
Avatar of EYoung

ASKER

Jenn3,

I thought earlier that your suggestion would not work because nothing came out on my HP Laser Jet printer.  But I think the reason why it did not come out was because the output went to memory and no page eject was sent.  Since the label printer works differently (and has little to no memory), that may not be a problem.  

I am sending the program over to the user to see how it works.  This might work out just fine.  I am going on vacation and probably won't be able to get back to you for a while so I just decided to award the answer to you now.  When I find out, I will let you know.

Thanks for persevering and for the possible answer.

Regards,
EYoung