Elegant way to check variables before using them
Posted: 05 May 2017, 13:44
I want to have a message box if var and var
That is how I do it now:
The problem is, that in my real-life code var a is sometimes undefined. So, I don't want to see message box in this case, but it still appears:
That is my current way to fix this issue:
But I don't like this way, because it seems too ugly. Is there more elegant way for it? i.e. I'm searching something like this:
Code: Select all
a != "aaa"
Code: Select all
b != "bbb"
Code: Select all
a := "111"
b := "222"
if (a != "aaa" and b != "bbb")
MsgBox, Yes
Code: Select all
; a := "111" ; Commented line
b := "222"
if (a != "aaa" and b != "bbb")
MsgBox, Yes ; Now I don't want this message box to be appeared, but it is till shown, despite the fact that var a is now undefined
Code: Select all
; a := "111"
b := "222"
if ((a and b) and (a != "aaa" and b != "bbb"))
MsgBox, Yes
Code: Select all
; a := "111"
b := "222"
IfAllVarsDefined
{
if ((a and b) and (a != "aaa" and b != "bbb"))
MsgBox, Yes ; This message box will not be shown now. Ant that is good.
}