|
-
Apr 22nd, 2003, 03:03 PM
#1
Thread Starter
Addicted Member
Logic Flow Problem, Please help tearing my hair out!
This is a flow issue.
Ok, going try to explain this as best I can.
Right now what my program does is takes items that are checked in a Checked List Box and compares them to a specific registry key. Currently everything is working great however there are times that a driver might be installed on a system and there are no printer objects associated with it in which case I want to state so in the txtLog. However if you follow the logic below you will see what I am running into (Yes I am a beginner VB programmer). What happens is in the For Each statement is that the txtLog is overrun with the text from the Else statement because it is doing it For Each.
IE: In otherwords if I have 1 item selected in the listbox it checks all 3 of the printers installed against the currently installed drivers and comes back with:
Not in Use
Not in Use
Found It!
If I take out the else statement then all is well however there are times when someone might select an item in the listbox that does not have a printer associated with it in which case I would like for them to know what is going on.
Thanks.
Jim
VB Code:
Dim prnCount As Integer
Dim strPrinter As String
Dim strlbText
Dim strDriver
envstrOS = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
' LISTS ALL OF THE PRINTER OBJECTS INSTALLED ON THE SYSTEM.
Dim RegKey As RegistryKey = Registry.LocalMachine.CreateSubKey( _
"SYSTEM\CurrentControlSet\Control\Print\Printers")
Dim SubKeys() As String = RegKey.GetSubKeyNames()
' GOES THROUGH THE LIST OF PRINTERS ONE AT A TIME
If SubKeys.Length > 0 Then
For prnCount = 0 To SubKeys.Length - 1
strPrinter = (SubKeys(prnCount))
' QUERIES THE REGISTRY KEY "PRINTER DRIVER" TO DETERMINE WHAT DRIVER A PRINTER OBJECT USERS.
Dim DrvRegKey As RegistryKey = Registry.LocalMachine.OpenSubKey( _
"SYSTEM\CurrentControlSet\Control\Print\Printers\" & strPrinter)
Dim objPrinterDriver As Object = DrvRegKey.GetValue("Printer Driver")
' CHECKS AGAINST A CHECKED LISTBOX TO SEE IF ANY OF THE ITEMS CHECKED MATCH THE PRINTER DRIVER FOUND ABOVE
For Each strDriver In lbDrivers.CheckedItems
If strDriver = objPrinterDriver Then
txtLog.AppendText(strPrinter & " uses " & strDriver)
txtCombined.AppendText("\\" & envstrOS & "\" & strPrinter & "," & "\\" _
& envstrOS & "\" & strPrinter & ControlChars.CrLf)
Else
' --- HERE IS THE PROBLEM, WITH THE ELSE STATEMENT ---
txtLog.AppendText("Driver " & strDriver & " is not in use by any printer object")
End If
Next
Next prnCount
End If
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
|