Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
| Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2004, 01:05 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Printing a VB Text Box Directly To a Printer

Hi All,

  I hope this is a simple question someone can answer for me, so here goes. I am currently working on a GUI in VB6 for a 911 center in which I need to be able to have the print button print directly to a printer over a serial connection without bringing up a print dialog box because the operators can't have any windows popping up in front of the caller info. The only thing that needs to be sent to the printer is the data contained within a normal text box. Thanks for any help I can get!

-CB

 
Old February 13th, 2004, 01:14 PM
Friend of Wrox
 
Join Date: Aug 2003
Location: , , .
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The Printer hasa hidden function print that works as follows:

Printer.Print textBox1.text
 
Old February 13th, 2004, 02:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Be careful here.

First of all, the user must have a default printer installed in her/his machine, otherwise the Printer object is nothing.
The Print method prints starting at the CurrentX,CurrentY coordinates (default 0,0 maybe you want to change those). If the text box is set to word wrap, the Text property is a long string without newlines, thus can easily go outside the page border. Finally, you have to invoke the Printer.EndDoc method to print the page after you are done with all the printing. To delete the print job, just call Printer.KillDoc.
More info in the "Printer Object, Printers Collection" VB/MSDN help page

Marco


Quote:
quote:Originally posted by Yehuda
 The Printer hasa hidden function print that works as follows:

Printer.Print textBox1.text
 
Old February 13th, 2004, 02:27 PM
Friend of Wrox
 
Join Date: Aug 2003
Location: , , .
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can set the default Printer through the printers collection. But Marco is right, it definitely would pay to read up more on the printer and printers object before using it.
 
Old February 13th, 2004, 05:38 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, Well what if I don't necessarily want to use the default printer, but one of the other predefined printers. I'm not sure they want the Ambulance printer to be their default printer for all apps, just for this one GUI when they press the print button. I also already have the contents printed out to a txt file, so it's possible just to print the contents of that file if it makes it easier.

Thanks,
CB

 
Old February 16th, 2004, 01:22 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does anyone have a way to change the default printer in a vb6 method? This way I can change it, print the text, then change it back all at the same time. Thanks.

CB

 
Old February 16th, 2004, 01:54 PM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it!

Dim p As Printer

For Each p In Printers
  ' Do something here
  If p.DeviceName = strSavedPrinter Then
    ' Change current printer and/or settings
    Set Printer = p
  End If
Next p

This pretty much solves my problem, thanks all!

CB





Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing problem dot matrix printer using VB.Net sukhsinghin@yahoo.com Crystal Reports 0 February 21st, 2006 11:29 AM
Printing directly leo_vinay ASP.NET 1.0 and 1.1 Basics 0 October 26th, 2005 11:17 PM
VB TEXT BOX VALUE akash VB How-To 2 April 29th, 2005 10:51 AM
Printing from a rich text box snowy0 VB.NET 2002/2003 Basics 2 April 24th, 2004 10:04 AM
Printing directly to a printer Louisa VB.NET 2002/2003 Basics 4 January 16th, 2004 09:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.