Solved

Open (printer) for output???

Posted on 2004-08-27
10
1,333 Views
Last Modified: 2008-03-03
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.
0
Comment
Question by:EYoung
10 Comments
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11918670
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.

0
 
LVL 7

Expert Comment

by:Jenn3
ID: 11918924
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

0
 
LVL 7

Expert Comment

by:_agj_
ID: 11919409
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.
0
 
LVL 10

Expert Comment

by:anv
ID: 11919458
i dont think u'll have to specify the default printer here...

just use print command
0
 
LVL 7

Expert Comment

by:Jenn3
ID: 11920496
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:ajaypappan
ID: 11921770
0
 
LVL 7

Author Comment

by:EYoung
ID: 11921992
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.
0
 
LVL 7

Accepted Solution

by:
Jenn3 earned 50 total points
ID: 11922462
Yes, you're right not to follow... as i didn't misunderstood you have coded earlier. heheheee.. sorry ;P

I am curious, is there are reason not to use something like this?

Printer.Print
Printer.Print "Print line 1"
Printer.Print "Print line 2"
Printer.Print "Print line 3"
Printer.Print

0
 
LVL 7

Expert Comment

by:Jenn3
ID: 11922466
I mean.. i misunderstood what you have coded earlier.
0
 
LVL 7

Author Comment

by:EYoung
ID: 11923352
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now