Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting ONLY valid Printers 1

Status
Not open for further replies.

MichaelRed

Programmer
Dec 22, 1999
8,410
US
There appear to be several &quot;options&quot; for identifying the _defined_ printers.&nbsp;&nbsp;How does one limit the list to those which are _ACTUALLY_ &quot;available&quot; (e.g. on-line as a usable resource, wheather on a network or locally?).&nbsp;&nbsp;Presenting Users with of all the printers ever defined for their machine - when many of them are not currently available seems contrary to the concept of making things &quot;user friendly&quot;<br>
 
Since no one else acceped this challengs, I (mistakenly) thought I could at least find out something about the printers.&nbsp;&nbsp;First guess was that if I could change some propertry of the printer, hten it MUST be on-line/available.&nbsp;&nbsp;This, it would appear, IS NOT the way to go. It just digs a deeper hole. Below is the (sad) tale of woe.<br><br>Vb6 (Title Bar)<br><br>X This program has performed an illegal operation and will be shut down.<br><br> If the problem persist, contact the vendor.<br><br>(Text Box/Details):<br>VB6 has caused an invalid page fault in module KERNEL32.DLL at 015f:bff7a4a3.<br> Registers:<br> EAX=00000000 CS=015f EIP= bff7a4a3 Eflags=00010206<br> EBX=00000000 SS=0167 ESP=007ff0b0 EBP=007ff0c0<br> ECX=01740028 DS=0167 ESI=01740000 FS=128f<br> EDX=00000124 ES=0167 EDI=0174000c GS=0000<br> Bytes at CS:EIP:<br> 8b 03 25 fc ff ff 0f 3b 45 0c 0f 83 81 00 00 00<br> Stack dump:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“00000000&nbsp;&nbsp;00000030&nbsp;&nbsp;bff51173&nbsp;&nbsp;000080bc&nbsp;&nbsp;&nbsp;007ff0d4”<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“bff88d9b&nbsp;&nbsp;&nbsp;01740000&nbsp;&nbsp;00000124&nbsp;&nbsp;00000000&nbsp;&nbsp;00000000”<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“004cf84a&nbsp;&nbsp;&nbsp;01740000&nbsp;&nbsp;00000000&nbsp;&nbsp;00000120&nbsp;&nbsp;00000000”<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;“007ff184”<br><br>The above is the expanded critical error from vb6 when attempting to get/change the properties of the non existant printer.&nbsp;&nbsp;The bos is reprinted in case there is some information in the “details” which help resolving the problem.&nbsp;&nbsp;Bottom version is just the scroll bar at the bottom of the text box.<br>&nbsp;Trying to print the above to the non existant printer returns the following error Message (plus a msgbox to let the user know the document was deleted).<br><br><br><br>&nbsp;‘Below is the code which raises the above errors.&nbsp;&nbsp;The reason for the numerous open/close statements for the text file (for those who may be curious) is that when VB causes the error, it cannot do the file close processs so it can never have any information in it (although written, the failure to (Properly) close leaves it as a zero length file).<br><br>The intent/purpose of the following is to give the user a list of AVAILABLE printers to select from.&nbsp;&nbsp;The “printers collection” gives a list of printer drivers which are installed, NOT a list of those which are “on-line” in the current environment.<br><br>Fox Pro offers a “PrintStatus()” command which returns .T. ¦ .F. to denote the “On-Line” status of the device.&nbsp;&nbsp;Documentation for this refers to :Sys(13).&nbsp;&nbsp;This documentation also notes that PrintStatus() always returns .T. for printers “ … printers connected through the Windows …”&nbsp;&nbsp;I am trying to achieve this result with out the limitation (e.g. I always want to be able to determine if the printer is “On-Line” Or “Ready”.<br><br>The Common Diaglog control for printers also shows a printer “status” in the example, but does not elaborate on what the status actually reflects.<br><br>The form consistsm of a combo box and two command buttons.&nbsp;&nbsp;the command buttonns are &quot;Select&quot; and &quot;Exit&quot;.&nbsp;&nbsp;This code is SUPPOSED to fill the combo box with printer names. (oh-by the way, IT DOESN'T)!<br><br>_____________________________Start of code_______________________<br><br>Private Sub Form_Load()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim Prtr As Printer<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyOr As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyFil As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyPrtrName As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyPrtrHdc As Long<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'Open Text File to Doc the Problem<br>'&nbsp;&nbsp;&nbsp;&nbsp;MyFil = FreeFile<br>'&nbsp;&nbsp;&nbsp;&nbsp;Open &quot;C:\My Documents\PrtrErr.Txt&quot; For Append As MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'Just Empty the List<br>'&nbsp;&nbsp;&nbsp;&nbsp;If (cboSelPrn.ListCount &gt;= 0) Then<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;While cboSelPrn.ListCount &gt; 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cboSelPrn.REMOVEITEM (0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wend<br><br>'&nbsp;&nbsp;&nbsp;&nbsp;End If<br><br>&nbsp;&nbsp;&nbsp;&nbsp;MyPrtrName = Printer.DeviceName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Capture Current<br><br>&nbsp;&nbsp;&nbsp;&nbsp;For Each Prtr In Printers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On Error GoTo NoPrtr<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Loop through What we Think is available<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set Printer = Prtr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'(Temporaily) Make this PRTR the Selected<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyOr = Printer.Orientation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Capture Current Setting<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If ((Err) = 482) Then<br>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If ((MyPrtrHdc = Printer.hDC) = 482) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GoTo NoPrtr<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Open Text File to Doc the Problem<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyFil = FreeFile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open &quot;C:\My Documents\PrtrErr.Txt&quot; For Append As MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'First Print to File<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFile, &quot;Date/Time: &quot; & Now<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, &quot;Name: &quot; & Prtr.DeviceName<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, &quot;Orientation: &quot; & MyOr<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, &quot;Hdc: &quot; & MyPrtrHdc<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Close #MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Now Change IT!!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If (MyOr = vbPRORPortrait) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Printer.Orientation = vbPRORLandscape<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Open Text File to Doc the Problem<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyFil = FreeFile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open &quot;C:\My Documents\PrtrErr.Txt&quot; For Append As MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print MyFil, &quot;Orientation: &quot; & Printer.Orientation<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Close #MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Printer.Orientation = vbPRORPortrait<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Open Text File to Doc the Problem<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyFil = FreeFile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open &quot;C:\My Documents\PrtrErr.Txt&quot; For Append As MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, &quot;Orientation: &quot; & Printer.Orientation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Close #MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If (Printer.Orientation = MyOr) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'If we changed it, It must be available!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'So Add it to the List<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cboSelPrn.AddItem (Prtr.DeviceName)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Open Text File to Doc the Problem<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyFil = FreeFile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open &quot;C:\My Documents\PrtrErr.Txt&quot; For Append As MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, &quot;# Printers Added: &quot; & cboSelPrn.ListCount<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, String(30, &quot;_&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print #MyFil, &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Close #MyFil<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'If we changed it, Restore it.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'If we couldnt change it, It makes NO Difference!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Printer.Orientation = MyOr<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoEvents<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>NoPrtr:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Next Prtr<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'After all the Gyrations, We need to Reset the Printer<br>&nbsp;&nbsp;&nbsp;&nbsp;'(all of the above is JUST to fill the combo box with VALID printers!)<br>&nbsp;&nbsp;&nbsp;&nbsp;For Each Prtr In Printers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If (Prtr.DeviceName = MyPrtrName) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set Printer = Prtr<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit For<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;Next Prtr<br><br>End Sub<br><br>________________________End Of Code__________________________<br><br><br>&nbsp;The following is the result (printout) of executing the above code.<br><br>Date/Time: 6/28/00 9:53:25 AM<br>Name: Microsoft Fax<br>Orientation: 1<br>Hdc: 0<br>Date/Time: 6/28/00 9:53:25 AM<br>Name: Rendering Subsystem<br>Orientation: 1<br>Hdc: 0<br>Date/Time: 6/28/00 9:53:25 AM<br>Name: HP 2000C Printer<br>Orientation: 1<br>Hdc: 0<br><br><br>The Printer which (aparently) causes this problem is not available on t he network when this occurs.<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top