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.
I am sorry, my first post was under a different assumption. I thought you were writing to a log file. You are only writing to a text box, is this correct? I don't understand what is going on. There shouldn't be a problem adding more text to the text box, whether it is in the first part of an if, or the else clause.
If it is a small project, you can zip it and post it here, I will look at the whole thing. I am having problems understanding exactly what it is supposed to do.
' --- HERE IS THE PROBLEM, WITH THE ELSE STATEMENT ---
txtLog.AppendText("Driver " & strDriver & " is not in use by any printer object")
End If
Next
Where it says --- HERE IS THE PROBLEM, WITH THE ELSE STATEMENT --- here is what happens.
In the:
Code:
If strDriver = objPrinterDriver Then
It goes through the For Each items checked in the CheckedListBox section and if there is a match it outputs to the two text boxes. This works great. However what I wanted to do was put a little bit of information in there If what they had selected in the CheckListBox did not have a match the just to append that to the text box. However what I am running into is that if the For Each (there are two "FOR" statements if you look at the code above) loop runs 50 times and there is only 1 match then I am getting that one match in the text box and 49 Not Matched.
So if for example if Jim is the only item checked in the CheckListBox and there are a list of 100 names in the For Each loop then I would get 99 NOT Matched and 1 matched all appened to the text file.
I want it so it only appends if it is not matched and only once, not each time the loop runs.
I hope that made it more clear. If you still need to post it let me know and I will put it up there.
Thanks,
Jim
Last edited by jlegan; Apr 22nd, 2003 at 08:26 PM.
If you have at least two printers installed on your system run the program and hit Generate List. Once you see all of the printer drivers installed on your system select one of them and click Generate List File.
You will see output that looks like this:
Code:
Driver "Xerox DocuPrint P1210" is not in use by any printer object
"P1210" uses "Xerox DocuPrint P1210"
In this case P1210 is the name of the Printer Object in the Printers Windows (Start > Settings > Printers) and "Xerox DocuPrint P1210" is the name of the driver installed for it. However since it goes thru a "For" statement for each driver on the system (ie why you need more than one printer installed to see the issue) then you will get the syntax listed above which inaccurately says that the driver is not in use by any printer object and then while doing the For loop it finally reaches and match and writes the proper data, stating which printer object uses that driver.
What I am trying to do is only get the "Driver XXXXXXX is not in use by any printer object" in the txtLog if there are no matches, somehow delaying that Append to that box until after the For loop completes that round of searching and before moving onto the next.
The code you provided is what I came up with today after a few hours of toying around but still ran into the problem above.
If you could offer a little more guidence I would appreciate it, I know I was close earlier but I am just missing that final piece.
Thanks as always,
Jim
Last edited by jlegan; Apr 22nd, 2003 at 11:11 PM.
I will have to look at it tomorrow, my mind is becoming shot right now, and I still have some stuff to solve in my own app. I will take a look at it tomorrow when I have fresh eyes.
Also, I am working from a laptop that doesn't have any printers or drivers installed, so it is kind of hard to test it. Talk to you later about it, k.
This is the last time I will write in on this issue. If anyone has any advice I would appreciate it. This is the only thing that is preventing me from finishing this program.