Sign in to follow this  
Followers 0
rudi

"IF NOT $FOO=$BAR" is giving faulty results, if $foo!=$bar ?

6 posts in this topic

#1 ·  Posted (edited)

Hello everybody :whistle:

I think I miss something very basic testing strings?

I'm using AutoIT3 Version 3.2.4.9 and SCITE 1.68 (Same results on WinXP-SP2 and Win2003-R2, SP2, German Ed.)

Here is what I tested, and I do not understand the results:

$dummy="\\"

;Test One: Values are *NOT* equal.
if $dummy="C_" Then
    MsgBox(0,"1: 'true'","")
Else
    MsgBox(0,"1: 'false'","correct result")
EndIf

;Test Two: Values *ARE* equal
if $dummy="\\" Then
    MsgBox(0,"2: 'true'","correct result")
Else
    MsgBox(0,"2: 'false'","")
EndIf

;Test Three: Values are *NOT* equal, *NOT* is used, so should give a true
if not $dummy="C_" Then
    MsgBox(0,"3: 'true'","")
Else
    MsgBox(0,"3: 'false'","WRONG result: $Dummy = " & $dummy & @lf & @lf & 'if not $dummy="C_"' & @lf & @lf & 'The Values are *NOT* equal. "IF NOT..." was used, so should give "TRUE"')

EndIf

;Test Four: Values *ARE* equal, *NOT* is used, so should give a false
if not $dummy="\\" Then
    MsgBox(0,"4: 'true'","This would be displayed, if 'if NOT' would generally fail")
Else
    MsgBox(0,"4: 'false'","Here" & @lf & @lf &"'if not ...'" & @lf &@lf &"*DOES* work fine: Values *ARE* equal, 'if not ...' was used, resulting 'false' (correct)")
EndIf


;###################################################################################


$dummy="C_"
MsgBox(0,"info","Now $dummy is set to ""C_""",3)

; 5: Values *ARE* equal ==> true
if $dummy="C_" Then
    MsgBox(0,"5: 'true'","correct result")
Else
    MsgBox(0,"5: 'false'","")
EndIf

; 6: Values *NOT* equal ==> false
if $dummy="\\" Then
    MsgBox(0,"6: 'true'","")
Else
    MsgBox(0,"6: 'false'","correct result")
EndIf

; 7: NOT used. Values equal. ==> false
if not $dummy="C_" Then
    MsgBox(0,"7: 'true'","")
Else
    MsgBox(0,"7: 'false'","Here" & @lf & @lf &"'if not ...'" & @lf &@lf &"again *DOES* work fine: Values *ARE* equal, 'if not ...' was used, resulting 'false' (correct)")
EndIf

; 8: "IF NOT ... " will be used. Values are *NOT* equal ==> true
if not $dummy="\\" Then
    MsgBox(0,"8: 'true'","This should show up (it doesn't!)")
Else
    MsgBox(0,"8: 'false'","WRONG result: $Dummy = " & $dummy & @lf & @lf & 'if not $dummy="\\"' & @lf & @lf & 'The Values are *NOT* equal. "IF NOT..." was used, so should give "TRUE"')
EndIf
ExitoÝ÷ Ù8^µë-¶­#§µçm¢ëÁ«¢¶©jØl¶¸§Ó¶ÞPкÚ"µÍYÝÝ[ÓY
    ÌÍÑ]OI][ÝÉÌLÉÌLÉ][ÝÈ[ÈÝ]X[ÛÈ
Õ
[SÈ]
HHÝ[ÈÚ[ÝÚ]×ÉÌLÜ]   ÌLÜ][ÈÈHÛÛYÈÎÌLÜ] ÌLÜ]

:lmao:

Thanks for any suggestions,

Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yea, from Help file:

When more than one operator is used in an expression the order in which things happen is controlled by operator precedence. The precedence used in AutoIt is given below. Where two operators have the same precedence the expression is evaluated left to right.

From highest precedence to lowest:

NOT

^

* /

+ -

&

< > <= >= = <> ==

AND OR

Means "Not" takes place before "Equal".

Doesn't make sense logically, but that's how it is...

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

consider...

if not $dummy="C_" Then

(not $dummy) = "C_"

not ($dummy = "C")

Lar.

Ah! :lmao:

So my mistake was to consider that a "if not" == "!="

On my way to check this. Thanks a lot for your :whistle: FAST reply!!

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Ah! :whistle:

So my mistake was to consider that a "if not" == "!="

Yes! With brackets it's working as expected.

What about :lmao: adding the "!=" operator? Basically I wanted to use my faulty expression as I do not like "<>"...

Thanks once more, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

OMG! The autoit box broke again when he edited his first post. Look at the bottom of the OP's Autoit box!

PS: I agree that != would make things easier.

Share this post


Link to post
Share on other sites

OMG! The autoit box broke again when he edited his first post. Look at the bottom of the OP's Autoit box!

PS: I agree that != would make things easier.

Have we forgotten about "<>" ?

Ralph

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