Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

 

'---------------------------------------------
'How To: Choosing a Printer Device at Run time
'Posted: 07-June-00
'Author: Robert L Cannon
'
'Description: Sample program written in response
'to forum question. This shows a very basic
'example of how to allow the user to select the
'printer for the current program at run time. Some
'solutions end up changing the default printer for
'all apps which may not be what you want.
'---------------------------------------------

 
'Option Explicit

 
Private Sub Form_Load()
Dim P As Printer
' Display the current default printer name and port.
cboPrinters.Text = Printer.DeviceName
lblPort.Caption = Printer.Port
' Loop through the printers collection and check each printer name.
For Each P In Printers
' Skip any printers you don't want to appear in the combo box.
If P.DeviceName = "Rendering Subsystem" Then
'Don't add it to the combo box.
Else
' Add any printers you do want to appear in the combo box.
cboPrinters.AddItem P.DeviceName
End If
Next
End Sub

 
Private Sub cboPrinters_Click()
Dim P As Printer
' Loop through the printers collection and check each printer name.
For Each P In Printers
' If the printers collection name matches the printer selected in the
' combo box, display it's port.
If P.DeviceName = cboPrinters.List(cboPrinters.ListIndex) Then
lblPort.Caption = P.Port
Exit For
End If
Next
End Sub

 
Private Sub cmdOK_Click()
Dim P As Printer
' Loop through the printers collection and check each printer name.
For Each P In Printers
' If the printers collection name is the same as the printer selected
' in the combo box, set that printer as the applications default printer.
If P.DeviceName = cboPrinters.List(cboPrinters.ListIndex) Then
Set Printer = P
Exit For
End If
Next
' Optional message box.
MsgBox "All printing for this application will be sent to the " & _
Printer.DeviceName & " printer on " & Printer.Port, _
vbOKOnly, "Print"
Unload Me
End Sub

 
Private Sub cmdCancel_Click()
Unload Me
End Sub

 
'----------------------------
'Burt Abreu
'Visual Basic Explorer
'http://www.VBExplorer.com
'June 07, 2000
'----------------------------


Downloads

In IE right-click and select 'Save Target As...' or in Netscape right-click and select 'Save Link As...'

 

View Plain Text View Plain Text
Download Demo Project Download Demo Project
View Code Online Not Available





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.