Solved

Open (printer) for output???

Posted on 2004-08-27
10
1,374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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