Printers Collection for Visual Basic 6.0 Users
The Visual Basic 6.0 Printers collection has no direct equivalent in Visual Basic 2005.
In Visual Basic 6.0, the Printers collection is used to return information about available printers on a system. Typically, you iterate through the Printers collection to find a printer with certain attributes and then set that printer to be the default printer for your application. For example, you might choose a laser printer instead of a dot matrix printer.
In Visual Basic 2005, there is no direct equivalent for the Printers collection, and the model has changed: Rather than choosing a printer for your application, you should allow your users to make their own choices.
Acomponent can be used to present a list of available printers to the user. Properties for the printer selected by the user can be retrieved using the class.
The Printers collection in Visual Basic 6.0 has two properties: Item and Count. The PrintDialog component has no equivalent properties. The PrinterSettings class has an InstalledPrinters collection with Item and Count; however, this is a String collection and cannot be used to query the attributes of a printer.
Code Changes for the Printers Collection
The following code example illustrates the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2005.
Code Changes for Returning a List of Available Printers
The following example demonstrates populating a ListBox control with a list of available printers.
' Visual Basic 6.0 Dim X As Printer For Each X In Printers List1.AddItem X.DeviceName Next
When a Visual Basic 6.0 application is upgraded to Visual Basic 2005, any instances of the Printers collection are not upgraded and an upgrade error is issued. You will need to remove the code for the Printers collection and modify your code so that it uses a PrintDialog component.