Sign in to follow this  
Followers 0
Queener

Shorten Multiple If Statements?

4 posts in this topic

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.")

Share this post


Link to post
Share on other sites



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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.")

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0