Navigation:  Methods >

GetPrinters Method

Previous pageReturn to chapter overviewNext page


Returns a variant array (string) containing the names of all physical and logical printer devices installed on the system.







Where object evaluates to an ASP Printer object.



The GetPrinters method has these arguments:




PrinterCount(Optional). Variant (Integer) expression that returns the number of printers found.







This method returns a one-dimensional variant (string) array of 1 column x n rows with each element containing 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.


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 PrintDoc method and pass the printer name as argument to send the document to the selected printer as shown below:


Dim ASPPrn As ASPPrinterCOM.ASPPrinter


Private Sub Form_Load()

       Dim MyPrinters As Variant, I As Integer, PrnCount As Integer


       'Get the names of installed printers

       MyPrinters = ASPPrn.GetPrinters(PrnCount)


       'Populate the combo box with the names

       For I = 0 To PrnCount - 1

               Combo1.AddItem MyPrinters(I)



       'Select the first printer name to show in the combo text

       Combo1.ListIndex = 0

End Sub



Private Sub CommandPrint_Click()

       'Specify some document text

       ASPPrn.DocText="Hello World!"


       'Print the document on the selected printer

       ASPPrn.PrintDoc (Combo1.List(Combo1.ListIndex))

End Sub




See also the SetPrinter method.