Jump to content

if Not working incorrectly possible bug?


Recommended Posts

$not = 1
if Not $not = inputbox("test", 'Test for: '&$not) then
     msgbox(0, 'True', 'Then')
else
     msgbox(0, 'False', 'Else')
endifoÝ÷ Û^»§)à¶nÞr^¶×«Â­Ê©º×è®Ø^znµº1Áëaz¸­³Z+i·yø(¯H­jÊË!£-á%±é²Æ yº1ëb*.r§í7êz-

works wether $not =0 or anything else.

This is why i miss !=

Edited by Yeik
func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

Two things - 1.) != is the same as <> in basic. 2.) It is Boolean - thus it is either true or False. False == !True.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

$not = 1
if Not $not = inputbox("test", 'Test for: '&$not) then
     msgbox(0, 'True', 'Then')
else
     msgbox(0, 'False', 'Else')
endifoÝ÷ Û^»§)à¶nÞr^¶×«Â­Ê©º×è®Ø^znµº1Áëaz¸­³Z+i·yø(¯H­jÊË!£-á%±é²Æ yº1ëb*.r§í7êz-

works wether $not =0 or anything else.

This is why i miss !=

Maybe it's because you need some parentheses to be sure which part the NOT is applied to. Also, InputBox returns a string so you need to be careful when comparing a string to a number although AutoIt often produces the expected result.

$not = 1
 if Not ($not = Number(inputbox("test", 'Test for: '&$not) ) ) then
      msgbox(0, 'True', 'Then')
 else
      msgbox(0, 'False', 'Else')
 endif

As bo8ster says, != in C is <> in Basic but also in AutoIt and Pascal so you could have this

$not = 1
 if $not <> Number(inputbox("test", 'Test for: '&$not)) then
      msgbox(0, 'True', 'Then')
 else
      msgbox(0, 'False', 'Else')
 endif
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Maybe it's because you need some parentheses to be sure which part the NOT is applied to. Also, InputBox returns a string so you need to be careful when comparing a string to a number although AutoIt often produces the expected result.

$not = 1
 if Not ($not = Number(inputbox("test", 'Test for: '&$not) ) ) then
      msgbox(0, 'True', 'Then')
 else
      msgbox(0, 'False', 'Else')
 endif

As bo8ster says, != in C is <> in Basic but also in AutoIt and Pascal so you could have this

$not = 1
 if $not <> Number(inputbox("test", 'Test for: '&$not)) then
      msgbox(0, 'True', 'Then')
 else
      msgbox(0, 'False', 'Else')
 endif
My point was more to the effect that I find it odd how the Not takes the next value and will return, but i guess that is a feature so you can have
if  100 < I > 50 then
work correctly, instead of executing the whole statement, it just executes it as an AND/OR.

I guess i can use the <> with no issues, or make sure i use the correct parenthesis.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

My point was more to the effect that I find it odd how the Not takes the next value and will return, ...

You have not understood what is happening there ;) It doesn't just take the first value and return, but I think you should play with these things and find out.

... but i guess that is a feature so you can have

if 100 < I > 50 then work correctly, instead of executing the whole statement, it just executes it as an AND/OR.

I guess i can use the <> with no issues, or make sure i use the correct parenthesis.

As Richard Robertson says, that is not a valid AuotIt instruction but only because the variable has no leading ' .

This works

;Ex A
 $i = 45
 if  10 < $I > 0 then ConsoleWrite("True" & @CRLF)

and it is the same as

;Ex B
 $i = 45
 if  (10 < $I) > 0 then ConsoleWrite("True" & @CRLF)

;Ex C

but it is not the same as

$i = 45
 if  10 < ($I > 0) then ConsoleWrite("True" & @CRLF)

It is not always obvious which version (B or C) will behave the same as A, which is why parentheses are important.

If $a < $b > $c then ;in Basic

is

If ($a < $^_^ And ($b > $C) then;in AutoIt

Edit: Corrected Richard Robertson's name.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You have not understood what is happening there ;) It doesn't just take the first value and return, but I think you should play with these things and find out.

As Richard Robinson says, that is not a valid AuotIt instruction but only because the variable has no leading '$'.

This works

;Ex A
$i = 45
if  10 < $I > 0 then ConsoleWrite("True" & @CRLF)

and it is the same as

;Ex B
$i = 45
if  (10 < $I) > 0 then ConsoleWrite("True" & @CRLF)

;Ex C

but it is not the same as

$i = 45
if  10 < ($I > 0) then ConsoleWrite("True" & @CRLF)

It is not always obvious which version (B or C) will behave the same as A, which is why parentheses are important.

If $a < $b > $c then ;in Basic

is

If ($a < $^_^ And ($b > $C) then;in AutoIt

Yes, I understand, sorry about the i without the $, I have been writing too many python scripts lately.

but from my experimentation it does seem that "if Not 'str' = 'str'" the Not evaluates 'str' since it isn't null, or 0, or false (basically means the same thing) then it goes to the else statement.

Thanks for helping clear up the confusion. It has been oddly interesting. I will be more careful with my if statements from now on.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

Perhaps you should lookup Operator Precedence in the help.

WBD

Link to comment
Share on other sites

Perhaps you should lookup Operator Precedence in the help.

WBD

you mean where it says

NOT Logical NOT operationg e.g. Not 1 (false)

and highest precedence to lowest:

NOT

^, * /, + -, &, < > <= >= = <> ==

AND OR

I have read through it, a few times. the problem was i was thinking that the not would let the other run, and i could use it like i do !=, without thinking about the priority in which they run.

Whenever im coding in AutoIT, my help file is ALWAYS up on the next screen.

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

:)

Oh yes, sorry.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I think we like quoting and repeating ourselves. At least this gives me more posts!

func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...