Not =, or <>?

,

Good morning,
I often find myself debating whether to use not =, or <> in my BAQ condition expressions. Is one method better than the other? Is one used for some variable types and not others? Why choose one over the other?
Thanks!
Nate

1 Like

I think it’s the same thing as far as the actual execution goes. For me, I almost NEVER look at the NOT checkbox. It’s just not something I typically use.

Technically speaking, the <> is an operator, while NOT is simply negating the operation:
if Part.PartNum <> 'ABC' returns TRUE, then doing it as NOT Part.PartNum = 'ABC' is simply returning NOT FALSE which is the same result. I don’t think there’s a performance difference between the two.

1 Like

For integers or strings, = or <> doesn’t matter but when you get to numbers with decimals, then I use extra care. If I want to know if two real, float, etc are “equal enough”, I will write something like:

if (abs(amt1 - amt2)) < 0.001) 
{ ...

Subtracting the two numbers and checking if the absolute difference is less than the precision I’m interested in, is more robust than the equality or inequality operators. This is really something to be careful with when looking at loop ending conditions!

4 Likes

How do you do

NOT… IN

or

NOT… ISNULL

without it?

image

1 Like

Oh, I use it, but I don’t think to look there because I do it so rarely. When troubleshooting others’ BAQs I never think to look at that on any of the criteria.

I normally would not use it unless I am doing something more complicated like a formula with two equates and one surrounding not. For example:
Not (a=1 and B=2)
The above is not the same as
A<>1 and B<>2
So, there are good reasons to use it.

1 Like

I think java has functionality that allows comparing a string to a number. And a special operator to make sure they are the same type.

var s = "2";
var i = 2;
var b = (s == i); // vab b will be TRUE  "2" equals 2
b = (s === i); // vab b will be FALSE  "2" does not equal2

And if you ever need to make complex logic and are limited by the the UI (like on a dashboard filter condition), remember the boolean math adage, “Break the line, change the sign”

some conventions:
/ - NOT the following. /A is NOT A, /(A+B) is NOT (A OR B)
+ - OR. A+B is A OR B
* - AND A*B is A AND B

/(A + B) (the line is over the whole expression)
becomes /A * /B

Its all much easier on paper when you can draw the line over the expression parts

_____             _   _
A + B   becomes   A * B
NOT(A OR B) ---> NOT(A) AND NOT (B)

_____             _   _
A * B   becomes   A + B
NOT(A AND B) ---> NOT(A) OR NOT (B)
1 Like

in C# its is !=

1 Like

in c# you have other options too…

The following two if statements yield identical results

if (a != 1) {//do something}}

if !(a = 1) {//do something}}

Reason is the ! is a “not” which basically flips a true to a false, and a false to a true…
So… the following two lines are also the same (but dont do the first one… it is just confusing)

if !(a != 1) {//do something}}   //if not not equal

if (a = 1) {//do something}}    //if equal
1 Like

I think you mean?

if(a == 1) ...

I believe what you had would generate an error in C#.

In original C, it is a valid statement. But is equal to

a = 1; 
// Always do what's between the braces
1 Like

In some of my coding, I have actually made use of the

if (a = Class.Method() != 1)

Just to add confusion to the thread.

While unnecessary, I would have added parentheses for readability.

if ((a = Class.Method()) != 1)

Hey! You cleared up some of my confusion :angry:

1 Like