Queener Posted May 30, 2014 Posted May 30, 2014 How do you shorten these if statements? If _PrinterExist("Mil SHARP MX-3501") = 1 Then _RemovePrinter("Mil SHARP MX-3501") EndIf If _PrinterExist("Mil Quality SHARP MX-3501") = 1 Then _RemovePrinter("Mil Quality SHARP MX-3501") EndIf If _PrinterExist("Mil Copier Quality") = 1 Then _RemovePrinter("Mil Copier Quality") EndIf If _PrinterExist("Mil Copier West") = 1 Then _RemovePrinter("Mil Copier West") EndIf Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Moderators JLogan3o13 Posted May 30, 2014 Moderators Posted May 30, 2014 Look at ternary in the help file if a If-Then-Else scenario: ;pseudo _PrinterExist("Mil SHARP MS-3501") ? <Do If True> : <Do If False> Also check out Switch and Select statements in the helpfile. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Solution MHz Posted May 30, 2014 Solution Posted May 30, 2014 With many items, I usually consider an array. One example of array usage: ; split each printer by | with no count and loop through each printer For $printer In StringSplit('Mil SHARP MX-3501|Mil Quality SHARP MX-3501|Mil Copier Quality|Mil Copier West', '|', 2) If _PrinterExist($printer) Then _RemovePrinter($printer) Next ; below functions are for testing Func _PrinterExist($printer) ConsoleWrite('exists ' & $printer & @CRLF) Return 1 EndFunc Func _RemovePrinter($printer) ConsoleWrite('remove ' & $printer & @CRLF) EndFunc
Queener Posted May 30, 2014 Author Posted May 30, 2014 works perfectly. I didn't know we can use stringsplit as an array. Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now