|
-
Oct 28th, 2005, 09:36 AM
#1
Thread Starter
Lively Member
[RESOLVED] Printers.Count Error
Hi,
still having printer woes lol. This code gives me an "Data member or method not found" error in one project but not the other. If I use the Printers.Form1.Count then it works. I cant understand why it does in one but not the other. And ideas?
VB Code:
'Load up the Printers installed
Dim i As Integer ' For printer collection
For i = 0 To Printers.Count - 1 'Gets the printers installed on the sytem
cboPrinters.AddItem Replace(Printers(i).DeviceName & "[" & Printers(i).DriverName & "]", "[winspool]", "")
Next
cboPrinters.Text = Printer.DeviceName
'MsgBox Printers.Form1.Count
Thanks
John
Just an infant in VB years 
-
Oct 28th, 2005, 09:38 AM
#2
Re: Printers.Count Error
Try using VB.Printers as opposed to just Printers
VB Code:
Private MyPrinters As Printer
Private Sub Form_Load()
Dim MyPrinters As Printer
'add all installed printers to combo box (if any)
If VB.Printers.Count <= 0 Then
cboPrinters.AddItem "No Printer(s) Installed"
Else
For Each MyPrinters In Printers
cboPrinters.AddItem MyPrinters.DeviceName
Next
End If
cboPrinters.ListIndex = 0
End Sub
-
Oct 28th, 2005, 10:02 AM
#3
Thread Starter
Lively Member
Re: Printers.Count Error
Hack, Thanks.
When I first tried your example it errored also. So I rebooted and tried my original again in a new project and it worked as well as did yours.
So I went back to the one that would error and it still will error.
The only difference this time to last was placing Option Explicit from the very start of the project and not after it had failed.
Not sure what is up with that.
Just an infant in VB years 
-
Oct 28th, 2005, 10:09 AM
#4
Re: Printers.Count Error
 Originally Posted by jkmcgrath
The only difference this time to last was placing Option Explicit from the very start of the project and not after it had failed.
Not sure what is up with that. 
Hmmmm...all Option Explicit does (which you should have turned on by default) is require that you declare variables before using them. Without it your program shouldn't misbehave. It sounds like a coincidence.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|