Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Printer Control in VB6

Posted on 2011-10-23
4
Medium Priority
?
268 Views
Last Modified: 2012-05-12
I have a VB6 program that uses straight printer. type commands to the default printer.
I now need to print a logo and the Dim text fields.  
How do i add a printer control so that the user can select the printer they want?
Should my logo/data shoot to the printer directly or go to a Form first? (I am not using a database)  Please show instruction, Thank You
0
Comment
Question by:GarySB
4 Comments
 
LVL 50

Assisted Solution

by:Martin Liss
Martin Liss earned 1000 total points
ID: 37014371
Dim WhatYouWantToPrint As String
 

CommonDialog1.ShowPrinter
Printer.Print WhatYouWantToPrint, CommonDialog1.hDC

Open in new window

0
 
LVL 2

Expert Comment

by:pancholefty
ID: 37015058
This isn't a runnable answer to your question. It's a couple of building blocks that you may find useful if you want more control of your UI and/or your app needs to have the ability to send different jobs, such as reports vs.receipts, to different printers.  

In your Preferences dialog, the user picks the printer for the job from a combo (dropdown list). You can store the selection in a config file or similar for later.

 
Dim i       As Integer

With cboPrinters
    
    For i = 0 To Printers.Count - 1
        
        .AddItem Printers(i).DeviceName
            
    Next
        
End With

Open in new window


Then assign the selection to a global variable:

 
g_strPrinterName = cboPrinters.Text ' or read it from the config file

Open in new window


When you get ready to print:

 
Dim prn	As Printer

For Each prn In Printers

    If (prn.DeviceName = g_strPrinterName) Then

        Set Printer = prn
        Exit For

    End If

Next

Open in new window

0
 
LVL 14

Accepted Solution

by:
VBClassicGuy earned 1000 total points
ID: 37018680
Here's how I do it (excuse my use of Implicit variable declaration):

   Rem *** Save default printer ***
   For i% = 0 To Printers.Count - 1
      If Printers(i%).DeviceName = Printer.DeviceName Then
         SavedPrn% = i%   'this variable is a public (global) variable
         Exit For
      End If
   Next i%

' Select your printer here. I have a dialog for this, or use the common dialog.

' Do your printing...

   Rem *** Restore default printer ***
   Set Printer = Printers(SavedPrn%)

HERE IS HOW I PRINT A LOGO IN THE "HEADER" OF MY REPORTS:

(note that "Alpha" is the name of my opening "start" form that has the logo on it)
(this code allows me to call this routine from any other form)
(my logo is contained in the pctPrint PictureBox control)

   Alpha.pctPrint.ScaleMode = vbPixels
   start% = (Printer.ScaleWidth / 2) - (Alpha.pctPrint.Width / 2)
   Call Printer.PaintPicture(Alpha.pctPrint.Picture, start%, Printer.CurrentY)
   Printer.CurrentY = Printer.CurrentY + Alpha.pctPrint.Height
0
 

Author Closing Comment

by:GarySB
ID: 37021586
Both answers were exactly what I needed, Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

580 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