Mannyfresh15 Posted June 17, 2016 Share Posted June 17, 2016 (edited) Ok I was writing a script where variables change value and I need to find out which one is the smaller value but greater than 0. I've tried out some codes in different ways but none work ): I don't know what I'm doing wrong since it's very simple math test. Well I'm posting the diferent codes I wrote, hope to get some head ups... BTW I'm new to Autoit, scripting and things. Test 1 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 1 If $7 > 0 And $7 < $10 And $7 < $15 Then $seven = True If $10 > 0 and $10 < $7 and $10 < $15 Then $ten = True If $15 > 0 And $15 < $7 And $15 < $10 Then $fifteen = True ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 2 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 2 If $7 <> 0 And $7 < $10 And $7 < $15 Then $seven = True ; If $10 <> 0 and $10 < $7 and $10 < $15 Then $ten = True ; If $15 <> 0 And $15 < $7 And $15 < $10 Then $fifteen = True ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 3 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 3 If Not $7 = 0 And $7 < $10 And $7 < $15 Then $seven = True ; If Not $10 = 0 and $10 < $7 and $10 < $15 Then $ten = True ; If Not $15 = 0 And $15 < $7 And $15 < $10 Then $fifteen = True ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 4 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 4 If Not $7 = 0 Then if $7 < $10 And $7 < $15 Then $seven = True EndIf ; If Not $10 = 0 Then If $10 < $7 and $10 < $15 Then $ten = True EndIf ; If Not $15 = 0 Then If $15 < $7 And $15 < $10 Then $fifteen = True EndIf ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 5 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 5 If ($7 > 0) And ($7 < $10) And ($7 < $15) Then $seven = True If ($10 > 0) and ($10 < $7) and ($10 < $15) Then $ten = True If ($15 > 0) And ($15 < $7) And ($15 < $10) Then $fifteen = True ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 6 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 6 If ($7 <> 0) And ($7 < $10) And ($7 < $15) Then $seven = True ; If ($10 <> 0) and ($10 < $7) and ($10 < $15) Then $ten = True ; If ($15 <> 0) And ($15 < $7) And ($15 < $10) Then $fifteen = True ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 7 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 7 If Not ($7 = 0) And ($7 < $10) And ($7 < $15) Then $seven = True ; If Not ($10 = 0) and ($10 < $7) and ($10 < $15) Then $ten = True ; If Not ($15 = 0) And ($15 < $7) And ($15 < $10) Then $fifteen = True ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 8 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 8 If Not $7 = 0 Then if $7 < $10 And $7 < $15 Then $seven = True EndIf ; If Not $10 = 0 Then If $10 < $7 and $10 < $15 Then $ten = True EndIf ; If Not $15 = 0 Then If $15 < $7 And $15 < $10 Then $fifteen = True EndIf ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Test 9 expandcollapse popup;simple mathematics test to see which number is smaller but greater then zero ;whichever number is the smallest but greater than zero becomes true at the end $seven = False $ten = False $fifteen = False ;in this test $7 and $15 cannot be true unless we change the value Global $7 = 0,$10 = 10,$15 = 15 ; ; ; ;test 9 If Not $7 = 0 Then if ($7 < $10) And ($7 < $15) Then $seven = True EndIf ; If Not $10 = 0 Then If ($10 < $7) and ($10 < $15) Then $ten = True EndIf ; If Not $15 = 0 Then If ($15 < $7) And ($15 < $10) Then $fifteen = True EndIf ; if $seven = True Then MsgBox(0,"Notice!", "Seven is True" & @LF & "$7 is greater than 0 but smaller than $10 y $15",0) EndIf ; if $ten = True Then MsgBox(0,"Notice!", "Ten is True" & @LF & "$10 is greater than 0 but smaller than $7 y $15",0) EndIf ; if $fifteen = True Then MsgBox(0,"Notice!", "Fifteen is True" & @LF & "$15 is greater than 0 but smaller than $7 y $10",0) EndIf Well that's all I got I've finally finished copying..... I know I'm provably doing so much lines for a simple thing but again I'm a noob. Edited June 20, 2016 by Mannyfresh15 Typo Link to comment Share on other sites More sharing options...

Moderators Melba23 Posted June 17, 2016 Moderators Share Posted June 17, 2016 Mannyfresh15, I would use an array like this: #include <MsgBoxConstants.au3> Global $aValues[20] $aValues[7] = 0 $aValues[10] = 10 $aValues[15] = 15 Local $iResult = 9999, $iIndex For $i = 0 To UBound($aValues) - 1 $iValue = Number($aValues[$i]) If $iValue > 0 And $iValue < $iResult Then $iResult = $iValue $iIndex = $i EndIf Next MsgBox($MB_SYSTEMMODAL, "Lowest value", $iIndex & @CRLF & $iResult) I think the code is self-explanatory. but please ask if you have any questions. 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...

jchd Posted June 17, 2016 Share Posted June 17, 2016 I'll just deal with test1, the rest being left as "an exercise to the reader". There, you test whether $7 is greater than 0, which it is not ($7 = 0 and 0 ≯ 0) so the whole condition is false and the first msgbox never shows. Then you test whether $10 < $7, which boils down to ask if 10 < 0, an obvious NO, so again the condition is false and nothing shows. Same for the third test, asking whether $15 < $7 (i.e. 15 < 0) and same as above. If you want to determine the smallest positive value from a bunch of variables, just do like Melba posted, use an array. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...

Mannyfresh15 Posted June 17, 2016 Author Share Posted June 17, 2016 M23, thanks for your example. However, it's quite confusing for a noob like me though. On the other hand I'm looking for something a lil more simple IDK if there is. You see in my test I just to identify the lowest value out of three different variables but exclude the one containing 0 is there is one. Link to comment Share on other sites More sharing options...

Moderators Melba23 Posted June 17, 2016 Moderators Share Posted June 17, 2016 Mannyfresh15, if you only ever have 3 variables then you can simplify the code a bit: #include <MsgBoxConstants.au3> ; Create an array with 3 elements Global $aValues[3] $aValues[0] = 0 ; Set these elements to your 3 values $aValues[1] = 10 $aValues[2] = 15 ; These are the placeholders for the value and its index within the array ; We set a ridiculously high value for the max value to start Local $iResult = 9999, $iIndex ; Loop through the array and check each value For $i = 0 To 2 ;This is the value we are checking $iValue = Number($aValues[$i]) ; if it is greater then zero and less that the current max If $iValue > 0 And $iValue < $iResult Then ; Store the value and its index $iResult = $iValue $iIndex = $i EndIf Next ; Display the lowest value that is greater then zero MsgBox($MB_SYSTEMMODAL, "Lowest value", $iIndex & @CRLF & $iResult) Clearer now? 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...

Mannyfresh15 Posted June 17, 2016 Author Share Posted June 17, 2016 8 minutes ago, jchd said: I'll just deal with test1, the rest being left as "an exercise to the reader". There, you test whether $7 is greater than 0, which it is not ($7 = 0 and 0 ≯ 0) so the whole condition is false and the first msgbox never shows. Then you test whether $10 < $7, which boils down to ask if 10 < 0, an obvious NO, so again the condition is false and nothing shows. Same for the third test, asking whether $15 < $7 (i.e. 15 < 0) and same as above. If you want to determine the smallest positive value from a bunch of variables, just do like Melba posted, use an array. Then I just gonna do something different 3 minutes ago, Melba23 said: Mannyfresh15, if you only ever have 3 variables then you can simplify the code a bit: #include <MsgBoxConstants.au3> ; Create an array with 3 elements Global $aValues[3] $aValues[0] = 0 ; Set these elements to your 3 values $aValues[1] = 10 $aValues[2] = 15 ; These are the placeholders for the value and its index within the array ; We set a ridiculously high value for the max value to start Local $iResult = 9999, $iIndex ; Loop through the array and check each value For $i = 0 To 2 ;This is the value we are checking $iValue = Number($aValues[$i]) ; if it is greater then zero and less that the current max If $iValue > 0 And $iValue < $iResult Then ; Store the value and its index $iResult = $iValue $iIndex = $i EndIf Next ; Display the lowest value that is greater then zero MsgBox($MB_SYSTEMMODAL, "Lowest value", $iIndex & @CRLF & $iResult) Clearer now? M23 Yes! It's a lot clearer now, thank you so much! Link to comment Share on other sites More sharing options...

Moderators Melba23 Posted June 18, 2016 Moderators Share Posted June 18, 2016 Mannyfresh15, Delighted to hear it. But when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unnecessarily. 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...

Mannyfresh15 Posted June 18, 2016 Author Share Posted June 18, 2016 Aye aye captain! 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 account## Sign in

Already have an account? Sign in here.

Sign In Now