SteelSeries Posted March 8, 2015 Share Posted March 8, 2015 (edited) Hi, Hopefully someone here will be able to help but I need a hand in converting this AutoIT piece of code or at least help me understand what's happening. http://pastebin.com/c1ivkKuQ I am trying to convert that snippet of code there for one of my C++ projects and as you can see in the above link I have tried to comment it with what I understand is happening but I am a little lost. For example where is the the iend and istart coming from? Are they just integer variables of the start of the array ( 0? ) and the end of the array? (could be 54 for example) ? Any help is appreciated! Thanks. Edited March 8, 2015 by SteelSeries Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 9, 2015 Moderators Share Posted March 9, 2015 SteelSeries,Welcome to the AutoIt forums. That looks like a hacked version of the _Array_MinIndex function in Array.au3 modified to work on 1D arrays only. The code works as follows: Func Mystery($dis, ByRef $minf, $iStart, $iend) ; pass and array, a var to hold the min index, and the start and end elements to search $avarray = $dis ; Copy the passed array to a local array If Not IsArray($avarray) Then Return $minf = "" ; If it is not a array then return and var holds an empty string If UBound($avarray, 0) <> 1 Then Return $minf = "" ; If the passed array is not 1D then return and var holds an empty string Local $iubound = UBound($avarray) + -1 ; Get the index of the top element of the array If $iend < 1 Or $iend > $iubound Then $iend = $iubound ; If passed end index is out of bounds or 0, set to end If $iStart < 0 Then $iStart = 0 ; If passed start index is < 0 then set to 0 If $iStart > $iend Then Return $minf = "" ; If start > end then return an empty string Local $iminindex = $iStart ; Assume index of lowest element is the start index Local $ichecknum = 0 ; Create a flag (cleared) For $i = $iStart To $iend ; Loop through the elements from start to end indices If Not IsNumber($avarray[$i]) Then ContinueLoop ; If element is not a number then ignore If Not $ichecknum Then $iminindex = $i ; If flag not set then set min index to this element index $ichecknum = 1 ; Set flag to show at least one number has been found If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminindex = $i ; If current min index element > this element, set this element as min Next $minf = $iminindex ; Set var to the current min index EndFunc ;==>MysteryBut I cannot help with the C++ part, sorry. >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...
SteelSeries Posted March 9, 2015 Author Share Posted March 9, 2015 SteelSeries, Welcome to the AutoIt forums. That looks like a hacked version of the _Array_MinIndex function in Array.au3 modified to work on 1D arrays only. The code works as follows: Func Mystery($dis, ByRef $minf, $iStart, $iend) ; pass and array, a var to hold the min index, and the start and end elements to search $avarray = $dis ; Copy the passed array to a local array If Not IsArray($avarray) Then Return $minf = "" ; If it is not a array then return and var holds an empty string If UBound($avarray, 0) <> 1 Then Return $minf = "" ; If the passed array is not 1D then return and var holds an empty string Local $iubound = UBound($avarray) + -1 ; Get the index of the top element of the array If $iend < 1 Or $iend > $iubound Then $iend = $iubound ; If passed end index is out of bounds or 0, set to end If $iStart < 0 Then $iStart = 0 ; If passed start index is < 0 then set to 0 If $iStart > $iend Then Return $minf = "" ; If start > end then return an empty string Local $iminindex = $iStart ; Assume index of lowest element is the start index Local $ichecknum = 0 ; Create a flag (cleared) For $i = $iStart To $iend ; Loop through the elements from start to end indices If Not IsNumber($avarray[$i]) Then ContinueLoop ; If element is not a number then ignore If Not $ichecknum Then $iminindex = $i ; If flag not set then set min index to this element index $ichecknum = 1 ; Set flag to show at least one number has been found If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminindex = $i ; If current min index element > this element, set this element as min Next $minf = $iminindex ; Set var to the current min index EndFunc ;==>Mystery But I cannot help with the C++ part, sorry. > M23 Amazing, thank you very much. I should be able to piece together what I need now. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 9, 2015 Moderators Share Posted March 9, 2015 SteelSeries,Glad I could help. 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...
SteelSeries Posted March 10, 2015 Author Share Posted March 10, 2015 (edited) SteelSeries, Glad I could help. M23 Sorry to bump this thread back into life, but I have another question Could this function be used for some kind of getting the smallest number in the array/getting the index of the lowest number? Edited March 10, 2015 by SteelSeries Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2015 Moderators Share Posted March 10, 2015 (edited) SteelSeries,It would need to be modified but the principle is exactly the same. This should do it: Func Mystery($dis, ByRef $minf, $iStart, $iend) ; pass and array, a var to hold the min value, and the start and end elements to search $avarray = $dis ; Copy the passed array to a local array If Not IsArray($avarray) Then Return $minf = "" ; If it is not a array then return and var holds an empty string If UBound($avarray, 0) <> 1 Then Return $minf = "" ; If the passed array is not 1D then return and var holds an empty string Local $iubound = UBound($avarray) + -1 ; Get the index of the top element of the array If $iend < 1 Or $iend > $iubound Then $iend = $iubound ; If passed end index is out of bounds or 0, set to end If $iStart < 0 Then $iStart = 0 ; If passed start index is < 0 then set to 0 If $iStart > $iend Then Return $minf = "" ; If start > end then return an empty string Local $iminvalue = $iStart ; Assume min value is value of the start index Local $ichecknum = 0 ; Create a flag (cleared) For $i = $iStart To $iend ; Loop through the elements from start to end indices If Not IsNumber($avarray[$i]) Then ContinueLoop ; If element is not a number then ignore If Not $ichecknum Then $iminindex = $avarray[$i] ; If flag not set then set min value to this element value $ichecknum = 1 ; Set flag to show at least one number has been found If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminvalue = $avarray[$i] ; If current min value > this value, set this value as min Next $minf = $iminvalue ; Set var to the current min value EndFunc ;==>MysteryM23Edit: Just seen your edit. The original code gave you the index of the lowest number - the above gives you the value itself. Look in the Help file at _ArrayMin & _ArrayMinIndex to see the difference. Edited March 10, 2015 by Melba23 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...
SteelSeries Posted March 10, 2015 Author Share Posted March 10, 2015 SteelSeries, It would need to be modified but the principle is exactly the same. This should do it: Func Mystery($dis, ByRef $minf, $iStart, $iend) ; pass and array, a var to hold the min value, and the start and end elements to search $avarray = $dis ; Copy the passed array to a local array If Not IsArray($avarray) Then Return $minf = "" ; If it is not a array then return and var holds an empty string If UBound($avarray, 0) <> 1 Then Return $minf = "" ; If the passed array is not 1D then return and var holds an empty string Local $iubound = UBound($avarray) + -1 ; Get the index of the top element of the array If $iend < 1 Or $iend > $iubound Then $iend = $iubound ; If passed end index is out of bounds or 0, set to end If $iStart < 0 Then $iStart = 0 ; If passed start index is < 0 then set to 0 If $iStart > $iend Then Return $minf = "" ; If start > end then return an empty string Local $iminvalue = $iStart ; Assume min value is value of the start index Local $ichecknum = 0 ; Create a flag (cleared) For $i = $iStart To $iend ; Loop through the elements from start to end indices If Not IsNumber($avarray[$i]) Then ContinueLoop ; If element is not a number then ignore If Not $ichecknum Then $iminindex = $avarray[$i] ; If flag not set then set min value to this element value $ichecknum = 1 ; Set flag to show at least one number has been found If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminvalue = $avarray[$i] ; If current min value > this value, set this value as min Next $minf = $iminvalue ; Set var to the current min value EndFunc ;==>Mystery M23 Edit: Just seen your edit. The original code gave you the index of the lowest number - the above gives you the value itself. Look in the Help file at _ArrayMin & _ArrayMinIndex to see the difference. Ah, brilliant! Thanks again, turns out that is exactly what it is; just a func to find the lowest number and its index. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 10, 2015 Moderators Share Posted March 10, 2015 SteelSeries,Again - glad I could help. 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 - I know what I 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...
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