GetPrinters Method


Top  Previous  Next


Returns a variant array (string) or a delimited string containing the names of all physical and logical printer devices installed on the system, including local and network printers.


Syntax

object.GetPrinters([PrinterCount], [ReturnAsDelimitedString])

Where object evaluates to a Raw Data Printer object.


The GetPrinters method has these arguments:


PartDescription  


PrinterCount(Optional). Variant (Integer) expression that returns the number of printers found.  
 
ReturnAsDelimitedString(Optional). Boolean expression specifying whether the printer names should be returned as an array or as a pipe (|) delimited string (default is False, which specifies that printer names are returned in an array).  
 



Remarks

If the ReturnAsDelimitedString argument is omitted or specified as False, the method returns a one-dimensional variant (string) array of 1 column x n rows, where each element contains the name of a physical or a logical printer found on the system, including network printers. The difference between a physical printer and a logical printer is that the first corresponds to a physical printer device attached to the system, while the last corresponds to a driver-type printer such as a FAX printer driver, a PDF printer driver, etc., where the output is either sent to a file or to a device other than a real printer device.

An example of the data array returned by this method is shown below:


      

HP DeskJet 690C

FAX Printer

PDF Printer Driver



In the above array, the first (top) element has index value 0, the second element has index value 1, etc. Note that the first element in the array will always contain the name of the default system printer.

If the ReturnAsDelimitedString argument is specified as True, a pipe-delimited string is returned (e.g. "HP Deskjet 690C|FAX Printer|PDF Printer Driver"). This is useful when using the object in programming languages other than Visual Basic and VB Script. For example, when using VC++ or Java Script, you may want to get a string rather than an array when calling this method, since arrays in these languages may be incompatible with the returned array type. You can use the Split() function (in VB, VBA, VB Script, Java Script, etc.) to split the printer names. Also, note that the first part of the string will always contain the name of the default system printer, as in the case of the array.

You can call this method to populate a combo box, for instance, with the names of installed printers so that the user can select a specific printer, then call the PrintRawData method and pass the printer name as argument to send the data to the selected printer as shown below:

Dim RDP As RawDataPrinter.Printer   

Private Sub Form_Load()  
   Dim MyPrinters As Variant, I As Integer, PrnCount As Integer  
 
   'Get the names of installed printers into an array  
   MyPrinters = RDP.GetPrinters(PrnCount)  
 
   'Populate the combo box with the names  
   For I = 0 To PrnCount - 1  
      Combo1.AddItem MyPrinters(I)  
   Next  
 
   'Select the first printer name to show in the combo text  
   Combo1.ListIndex = 0  
End Sub  
 
 
Private Sub CommandPrint_Click()  
   'Print data to the selected printer  
   RDP.PrintRawData ("Printed using Raw Data Printer!", , Combo1.List(Combo1.ListIndex))  
End Sub  
 


See also the SetPrinter method.