Roman Posted December 13, 2007 Share Posted December 13, 2007 Hello Look at this code: $a = 1 If $a = 1 Then MsgBox(0, "", "$a is 1") EndIf If Not $a = 2 Then MsgBox(0, "", "$a is NOT 2") EndIf Why i don't get the second message-box "$a is NOT 2"? Feel like an absolut beginner. :"> Where i am wrong? Regards, Roman. Link to comment Share on other sites More sharing options...
BrettF Posted December 13, 2007 Share Posted December 13, 2007 (edited) This method is better in my opinoin. Well for your purpose... $a = 1 If $a <> 2 Then MsgBox(0, "", "$a is NOT 2") EndIf Edited December 13, 2007 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
smashly Posted December 13, 2007 Share Posted December 13, 2007 Hi,$a = 1 If $a = 1 Then MsgBox(0, "", "$a is 1") EndIf If Not ($a = 2) Then MsgBox(0, "", "$a is NOT 2") EndIf Cheers Link to comment Share on other sites More sharing options...
therks Posted December 13, 2007 Share Posted December 13, 2007 It seems wrong to me that you'd have to parenthesise the $a = 2 part, I would assume it's later in the order of operations, but I guess not.To explain, what's happening is that the equation Not $a = 2 is actually made up of 2 comparisons, and the Not comparison is evaluating first because it's going left to right.So instead of this (which you probably expected):Not $a = 2= Not False= TrueWe're getting this:Not $a = 2= False = 2= FalseWhen you put brackets (parentheses) around the $a = 2 part, we're forcing that to evaluate first, like my first example.... Don't know if you needed that explanation, but if not then maybe someone else will learn from it. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 13, 2007 Share Posted December 13, 2007 (edited) It seems wrong to me that you'd have to parenthesise the $a = 2 part, I would assume it's later in the order of operations, but I guess not. To explain, what's happening is that the equation Not $a = 2 is actually made up of 2 comparisons, and the Not comparison is evaluating first because it's going left to right. So instead of this (which you probably expected): Not $a = 2 = Not False = True We're getting this: Not $a = 2 = False = 2 = False When you put brackets (parentheses) around the $a = 2 part, we're forcing that to evaluate first, like my first example. ... Don't know if you needed that explanation, but if not then maybe someone else will learn from it. It's not just left to right. There is an order of operations and NOT is the highest (first) operation. From the help file under Operators: 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 So if you evaluate If Not $a = 2, it will NEVER be True, because the (Not $a) will be performed first and then compared to 2. Any time you see "If Not ..." it should be a red flag to you. The above expression should be "If $a <> 2 Then". P.S. Is was able to find one special case where Not $a = 2. If $a = Binary("0xFFFFFFFC"): Global $avTest[3] = [2, 3, Binary("0xFFFFFFFC")] For $n = 0 To 2 $a = $avTest[$n] If Not $a = 2 Then ConsoleWrite("Debug: Not " & $a & " = 2" & @LF) Else ConsoleWrite("Debug: Not " & $a & " <> 2" & @LF) EndIf Next Edited December 13, 2007 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
therks Posted December 13, 2007 Share Posted December 13, 2007 It's not just left to right. There is an order of operations and NOT is the highest (first) operation.I guess I was (NOT True) in my assumption above. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Roman Posted December 14, 2007 Author Share Posted December 14, 2007 Thanks a lot for the explanation(s). Regards, Roman. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now