# How come 'NOT' does not work on string compares?

## Recommended Posts

I had a logic explosion in one of my scripts, and just figured out that 'NOT' does not work in string compares. Is that by design?

Demo of my problem:

```; Test string compares

\$Text1 = "One"
\$Text2 = "Two"

If \$Text1 = \$Text2 Then
MsgBox(32, "Compare with =", '"' & \$Text1 & '" is equal to "' & \$Text2 & '"')
Else
MsgBox(32, "Compare with =", '"' & \$Text1 & '" is not equal to "' & \$Text2 & '"')
EndIf

If Not \$Text1 = \$Text2 Then
MsgBox(32, "Compare with Not =", '"' & \$Text1 & '" is not equal to "' & \$Text2 & '"')
Else
MsgBox(32, "Compare with Not =", '"' & \$Text1 & '" is equal to "' & \$Text2 & '"')
EndIf

If \$Text1 == \$Text2 Then
MsgBox(32, "Compare with ==", '"' & \$Text1 & '" is equal to "' & \$Text2 & '"')
Else
MsgBox(32, "Compare with ==", '"' & \$Text1 & '" is not equal to "' & \$Text2 & '"')
EndIf

If Not \$Text1 == \$Text2 Then
MsgBox(32, "Compare with Not ==", '"' & \$Text1 & '" is not equal to "' & \$Text2 & '"')
Else
MsgBox(32, "Compare with Not ==", '"' & \$Text1 & '" is equal to "' & \$Text2 & '"')
EndIf

If \$Text1 <> \$Text2 Then
MsgBox(32, "Compare with <>", '"' & \$Text1 & '" is not equal to "' & \$Text2 & '"')
Else
MsgBox(32, "Compare with <>", '"' & \$Text1 & '" is equal to "' & \$Text2 & '"')
EndIf

If Not \$Text1 <> \$Text2 Then
MsgBox(32, "Compare with Not <>", '"' & \$Text1 & '" is equal to "' & \$Text2 & '"')
Else
MsgBox(32, "Compare with Not <>", '"' & \$Text1 & '" is not equal to "' & \$Text2 & '"')
EndIf```

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

hello

i have had the same problem : take a look here

If Not \$Text1 = \$Text2

(not \$text1) is first evaluated, and = is evaluated after.

Try

if not(\$text1 = \$text2)

##### Share on other sites

hello

i have had the same problem : take a look here

If Not \$Text1 = \$Text2

(not \$text1) is first evaluated, and = is evaluated after.

Try

if not(\$text1 = \$text2)

Ahh, I see, said the blind man...

Works the same way with numeric compares, I hadn't noticed that. Thanks!

I used ta couldn't spell poorgrammer, now I are one! Thanks to the AutoIT3 Forums!

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

## Create an account

Register a new account