MasonMill Posted January 18, 2011 Share Posted January 18, 2011 If i want to make this: if $x1 <> $x2 and $y1 <> $y2 within a limit like 10 or so, how do i write it? Is there a keyword? Something like: if $x1 <> range($x2, 10) and $y1 <> range($y2, 10) Thanks! Link to comment Share on other sites More sharing options...
JoHanatCent Posted January 18, 2011 Share Posted January 18, 2011 Try: $x1 = 170 $x2 = 180 $y1 = 2000 $y2 = 2010 $range = 10 If $x1 < $x2 + $range Or $x1 > $x2 - $range And $y1 < $y2 + $range Or $y1 > $y2 - $range Then MsgBox(0, '', 'Yes') Else MsgBox(0, '', 'No!') EndIf Link to comment Share on other sites More sharing options...
Malkey Posted January 18, 2011 Share Posted January 18, 2011 (edited) Try this. Local $x1 = 0, $y1 = 0 Local $x2 = 9, $y2 = 11 Local $iRange = 10 If (($x1 > $x2 - $iRange) And ($x1 < $x2 + $iRange)) And _ (($y1 > $y2 - $iRange) And ($y1 < $y2 + $iRange)) Then MsgBox(0, "Test 1", "$x1, $y1 is within the range of $x2, $y2", 2) Else MsgBox(0, "Test 1", "Out of range.", 2) EndIf ;== OR using WithinRange() function ======================= If WithinRange($x1, $x2, $iRange) And WithinRange($y1, $y2, $iRange) Then MsgBox(0, "Test 2", "$x1, $y1 is within the range of $x2, $y2", 2) Else MsgBox(0, "Test 2", "Out of range.", 2) EndIf Func WithinRange($a, $b, $range) If (($a > $b - $range) And ($a < $b + $range)) Then return True Else return False EndIf EndFunc @JoHanatCent If $x1 < $x2 + $range Or $x1 > $x2 - $range And $y1 < $y2 + $range Or $y1 > $y2 - $range Then will always be true for $range values > zero. Edited January 18, 2011 by Malkey Link to comment Share on other sites More sharing options...
CodyBarrett Posted January 19, 2011 Share Posted January 19, 2011 i could be mistaken, but doesn't this work? if $min <= $var <= $max then endif [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 19, 2011 Moderators Share Posted January 19, 2011 CodyBarrett, but doesn't this work?No - it is just luck that it seems to work in this case. Explanation: - 1. Remember AutoIt evaluates expressions of the same precedence in left to right order. - 2. Remember some operators (like >= and <=) return True/False. - 3. True is interpreted as 1 and False as 0. So let us look at the operations AutoIt is carrying out: expandcollapse popup$min = 3 $var = 3 $max = 3 ; Your suggestion If $min <= $var <= $max Then ConsoleWrite("Yes 1" & @CRLF) Else ConsoleWrite("No 1" & @CRLF) EndIf ; Which is actually processed like this If ($min <= $var) <= $max Then ConsoleWrite("Yes 2" & @CRLF) Else ConsoleWrite("No 2" & @CRLF) EndIf ; (3 <= 3) <= 3 ; True <= 3 ; 1 <= 3 ; True ; But does not work if processed like this If $min <= ($var <= $max) Then ConsoleWrite("Yes 3" & @CRLF) Else ConsoleWrite("No 3" & @CRLF) EndIf ; 3 <= (3 <= 3) ; 3 <= True ; 3 <= 1 ; False ; And your original fails if you reverse the order of the comparisons! If $max >= $var >= $min Then ConsoleWrite("Yes 4" & @CRLF) Else ConsoleWrite("No 4" & @CRLF) EndIf ; (3 >= 3) >= 3 ; True >= 3 ; 1 >= 3 ; False Remember the warning in the Help file: "False / True: These keywords should not be used in expressions as AutoIt will not detect this 'misuse' and the results will be unpredictable." I hope that is all clear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
4ggr35510n Posted January 20, 2011 Share Posted January 20, 2011 (edited) You are terrible complicating !!! $var1 = 5; $var2 = 10; $range = 7; If Abs($var1 - $var2) < $range Then MsgBox(0,'','Its in a range!') Use absolute value of the difference! Edited January 20, 2011 by 4ggr35510n Link to comment Share on other sites More sharing options...
CodyBarrett Posted January 20, 2011 Share Posted January 20, 2011 CodyBarrett, No - it is just luck that it seems to work in this case. Explanation: - 1. Remember AutoIt evaluates expressions of the same precedence in left to right order. - 2. Remember some operators (like >= and <=) return True/False. - 3. True is interpreted as 1 and False as 0. So let us look at the operations AutoIt is carrying out: expandcollapse popup$min = 3 $var = 3 $max = 3 ; Your suggestion If $min <= $var <= $max Then ConsoleWrite("Yes 1" & @CRLF) Else ConsoleWrite("No 1" & @CRLF) EndIf ; Which is actually processed like this If ($min <= $var) <= $max Then ConsoleWrite("Yes 2" & @CRLF) Else ConsoleWrite("No 2" & @CRLF) EndIf ; (3 <= 3) <= 3 ; True <= 3 ; 1 <= 3 ; True ; But does not work if processed like this If $min <= ($var <= $max) Then ConsoleWrite("Yes 3" & @CRLF) Else ConsoleWrite("No 3" & @CRLF) EndIf ; 3 <= (3 <= 3) ; 3 <= True ; 3 <= 1 ; False ; And your original fails if you reverse the order of the comparisons! If $max >= $var >= $min Then ConsoleWrite("Yes 4" & @CRLF) Else ConsoleWrite("No 4" & @CRLF) EndIf ; (3 >= 3) >= 3 ; True >= 3 ; 1 >= 3 ; False Remember the warning in the Help file: "False / True: These keywords should not be used in expressions as AutoIt will not detect this 'misuse' and the results will be unpredictable." I hope that is all clear. M23 oh! okay... i thought it would work because (by luck now you explained it) it has worked in several functions of mine. thanks for explaining why it wouldn't. [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 20, 2011 Moderators Share Posted January 20, 2011 CodyBarrett,i thought it would workWell, of course, it does work in some cases where the values are suitable - but it is best not to rely on it in more general coding for the reasons I explained above. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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