Grrrrrrrrrrr... I keep getting errors.
I can't figure out how to use the & / or operators in an if statement.
???Code:if (x < Y) & (y > Z) then
... yadda
end if
Printable View
Grrrrrrrrrrr... I keep getting errors.
I can't figure out how to use the & / or operators in an if statement.
???Code:if (x < Y) & (y > Z) then
... yadda
end if
try AND instead of &
VB Code:
If X < Y And Y > Z Then 'do code if both is true End If If X < Y Or Y > Z Then 'do code if one is true End If
Thanks guys. :blush:
You can also use the commonly forgotten( AndAlso OrElse) operators.
You absolutely SHOULD use AndAlso and OrElse. Those from a VB6 background are used to And and Or but things have changed. You should only use And and Or if you specifically want the second expression to be evaluated even if the first fails. In most cases it won't matter, and the miniscule improvement in performance won't be noticed, but there are instances where it is the difference between an unhandled exception or not, e.g.This code checks whether a form exists by testing whether it has never been created or it has been destroyed. If the first condition is True then the second condition is not evaluated, which is desireable. If Or was used instead, the second condition would still be evaluated and a NullReferenceException thrown. The moral of the story is that you should ALWAYS use AndAlso and OrElse unless there is a specific need to use And and Or.VB Code:
If myForm Is Nothing OrElse myForm.IsDisposed Then