×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Changing printers in VB

Changing printers in VB

Changing printers in VB

(OP)
I've written a program right now that will print barcodes to a printer. However unless the default printer is set up as the Eltron TLC 2622 (barcode printer), it will not print there. This is a pain b/c if I want to print out a document, I need to change back to my other printer continuously from the Printers in the control panel. Is there any code or way that I can make the one program use the Eltron printer, but have the default printer set up to another printer (like a deskjet)? I've found some code, but its for an excel spreadsheet only and doesn't work.

RE: Changing printers in VB

If you're using VB5/6, then it will only print to the default printer. I have code to change default printer in VB if that's what you need.
You can find the available printer names like this:

CODE


For a = 0 to Printers.Count - 1
Debug.Print Printers(a).Devicename
Next a
You could use the Instr function to find "Laser" for instance

CODE

If Instr(1,printers(a).devicename,"Laser") Then

To set the default printer once you decide the name:

CODE

For Each prtDev In Printers
If prtDev.DeviceName = "DMP" Then
Set Printer = prtDev
End If
Next

Note that the Printers collection is not available in VBA

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

UK steam enthusiasts: www.essexsteam.co.uk

RE: Changing printers in VB

I hope some well-versed in VB can provide a good solution for you. If not, you may be able to do what you want using Windows API calls, but that may involve changing your code to write first to a file, then finding the right printer, opening it, and writing RAW data streams to it, thus bypassing the normal PRINT route. I've done this with Fortran easily enough. I had to, because the OPEN statement in the version I have (Lahey LF95) doesn't provide for giving the name of a printer to be used. If it had, then I could have done that particular output with normal WRITE statements. If you wind up going the API route and need to see the Fortran equivalent, the collection of routines I put together for it can be retrieved from the "Code Repository" on the Lahey web site: www.lahey.com. The Windows API provides a lot of neat capability, at the expense of another level of complexity. HTH.

RE: Changing printers in VB

I think johnwm's solution is the best way to go with one addition, that being to reset the default printer after you've done.

CODE

Dim strDefPrtName   As String
Dim prtDev as Printer

Printer.TrackDefault = True
strDefPrtName  = Printer.DeviceName
For Each prtDev In Printers
   If (prtDev.DeviceName = "<Name of Barcode Printer>") Then
      Set Printer = prtDev
   End If
Next prtDev

<Print the Bar Code Labels>

For Each prtDev In Printers
   If (prtDev.DeviceName = strDefPrtName) Then
      Set Printer = prtDev
   End If
Next prtDev


   

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: Changing printers in VB

Hi,
the code
Printer.TrackDefault = True
will cause your program to track default printer, you sholud set it to false so your program will print to your selected device.
if you want to be sure, just save the default and re select it

Printer object has a nice help file in VB6 with examples

also visit

http://www.planet-source-code.com/vb/default.asp?lngWId=1
join it is free
all vb codes are catigorised, download what you need to know

another free site

http://www.vbcode.com/



Maged A. Mohamed
http://magedm.freeyellow.com
http://www.magedsoft.com

RE: Changing printers in VB

Hey Brad,

I was trying to write a program myself in VB for my Eltron printer but am having real difficulties with ELP2. All I want to do is print a bitmap on a label. Could you share some code with me that might solve my problem?

Cheers,

Rob

RE: Changing printers in VB

(OP)
Hey Robert,

What my code does is calls a crystal report that I had created with the proper size of the label and margin settings. Then it brings up a preview of the label (in crystal reports) and then when you click print, it prints the label to the default printer, which ends up being the Eltron. Sorry, I don't think that I have any code that'll be benefitial to you. What you might want to do is see if you can find or get a chunk of code that brings up paint or a picture viewer with your bitmap in it with the margins and settings all set up. Then set your Eltron to default and click the print button. Good luck and let me know if it turns out or not.

Brad

RE: Changing printers in VB

Thanks for your reply Brad. Your idea might work but I fear there are other obstacles I have to overcome first. Let me go into a little more detail about my problem and maybe you might be able to offer up some wisdom :):

The printer is connected properly. Windows Test Page printed to it, and the Eltron Create-A-Label software works fine. If I try to print a bitmap from Paint (say) however, it just ejects blank labels. From my VB.NET program where I create a bitmap to be printed, it prints just a small portion of the desired image down the centre of the label. To try and solve the problem therefore, I've tried to use EPL commands by sending them as raw data to the printer using code from http://support.microsoft.com/?scid=kb;EN-US;322090
, but have only had limited success.

Before explaining any further I guess what I need to ask is Are you familiar with EPL2? and if not, can you think of any way at all (using any software) that I could use to just print an image (bitmap). At least that would be a step in the right direction :)

Thanks again in advance,

Rob

RE: Changing printers in VB

(OP)
Hey Rob,

What size are the labels that you are using? Because what might be happening is that if say your label is 1x3 (inches) and you have white space around your bitmap, it may just be printing the white space. Theoretically though, it should just see the Eltron as another printer and print from paint. You can set up the page size/label size, margins and all that from the printer properties(which you already probably know). I'm not familiar with EPL2 language. The printer that I was using was an Eltron 2622/2722. I didn't have to use the PCL for the printer. One thing that you need to watch though is that some of the text MUST BE ASCII

Ex: crsReport1.FormulaFields.Item(1).Text = Chr$(39) & "PO#: " & strPONumber & Chr$(39)

This is just an example of a section of code that I put in. It calls a PONumber and turns it into a barcode, but I needed to use ASCII text in order for it to work (39 = ,).

Another thing that you have to watch is the drivers for the printer and the versions and such with ELP2.

All I can suggest is to try setting margins or somehow setting a border around the image from VB.net. That way you'll be able to see if the image is getting bigger or smaller on the label.

CrystalReportViewer.CRViewer1.Height = 400
CrystalReportViewer.CRViewer1.Width = 600

This code works to size the crystal reports window, so try something like this to size the image to the size of the labels.

Else, if you have a version of photoshop, try printing the label from there. Photoshop has many great features, and you may be able to find what your looking for there. I'll keep thinking about this though, and if I get any other brainwaves I'll let you know.

Keep me posted! :)

Brad

RE: Changing printers in VB

Hey Brad,

Thanks for all your help. I had a intensive session last night with the printer and managed to crack most all of my problems.

Although I did know about changing margins, I just hadn't thought to do so, and sure enough as soon as I added a PageSetupDialog in my program I was able to tweak and configure my printer correctly. Now the only work I have to do is similar to your original problem :)
I guess the problems I was having with ELP2 just had me sidetracked.

Speaking of which, the way in which my program prints a bitmap onto the printer seems to result in a fair amount of clarity loss, so I tried to persevere with ELP2 in order to create the image I wanted using printer commands alone. As you suspected, some of the text needed to be in ASCII, and I have since managed to get most of the commands to work. Strangely, some work when not in ASCII (which was helping to confuse me earlier, I think) and some dont work even when they ARE in ASCII. Strange...but at least a bulk of the issues are behind me.

Thanks again for your all of your time and help btw. I really do appreciate it.

Cheers,

Rob

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources