ericnail Posted November 11, 2010 Share Posted November 11, 2010 Okay, So i have 10 variables coming in and I need to find out which is the lowest in autoIT Is there a way to do this without using '_ArrayMinIndex' because the variables are all different rather than packed into on variable as an array. so in order to use the arrayminindex method i need to pack them all into a single array and I feel this wastes time and cpu power. Also, you cant use '_arrayMinIndex' with 2D arrays so even if I use it, I cant create a label for each array so when I get the min index i dont know what it is :/ Thanks, Eric Link to comment Share on other sites More sharing options...
ZacUSNYR Posted November 11, 2010 Share Posted November 11, 2010 If you know the variable, why would you not know the index of the Array? I'm trying to understand what you're doing. You have an example where you need to do this? I can think of some ways to do it but i'm curious why as well. Link to comment Share on other sites More sharing options...
BugFix Posted November 11, 2010 Share Posted November 11, 2010 (edited) If you don't like use arrays, you can try this: (up to 10 values in example function) Func _GetMin($n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) Local $min = $n1, $val For $i = 2 To 10 $val = Eval('n' & $i) If IsKeyword($val) Then ExitLoop If $val < $min Then $min = $val Next Return $min EndFunc Edited November 11, 2010 by BugFix Best Regards BugFix Link to comment Share on other sites More sharing options...
hannes08 Posted November 11, 2010 Share Posted November 11, 2010 Maybe you want to try something like this if you have several arrays to compare instead of just plain variables: Func _GetMin($n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) If IsArray($n1) Then Local $min = $n1[_ArrayMinIndex($n1)] Else Local $min = $n1 EndIf For $i = 2 To 10 If IsKeyword(Eval('n' & $i)) Then ExitLoop If IsArray(Eval('n' & $i)) Then $a2 = Eval('n' & $i) $min2 = $a2[_ArrayMinIndex($a2)] If $min2 < $min Then $min = $min2 Else If Eval('n' & $i) < $min Then $min = Eval('n' & $i) EndIf Next Return $min EndFunc Of course you still could replace the "_ArrayMinIndex" with your own function... Regards, Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
BugFix Posted November 12, 2010 Share Posted November 12, 2010 Than, i think, its better to use only one function to get min value from plain variables and/or 1D arrays. With recursive call it works fine: ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetMin ; Description ...: Gets min value from up to 10 single values and/or 1D-arrays ; Syntax.........: _GetMin($iStart, $n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) ; Parameters ....: $iStart start index from given arrays, if no arrays used you can set any (i.e. 0 or '') ; $n1...$n10 single values and/or 1D-arrays to get min value from ; Remarks .......: With arrays: all arrays using the same start index ; =============================================================================================================================== Func _GetMin($iStart, $n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) Local $min = $n1, $min2, $val If $n2 == 'sub' Then If UBound($n1) = $iStart +1 Then Return $n1[UBound($n1) -1] $min = $n1[$iStart] For $i = $iStart +1 To UBound($n1) -1 If $n1[$i] < $min Then $min = $n1[$i] Next Return $min EndIf If IsArray($min) Then $min = _GetMin($iStart, $min, 'sub') For $i = 2 To 10 $val = Eval('n' & $i) If IsKeyword($val) Then ExitLoop If IsArray($val) Then $min2 = _GetMin($iStart, $val, 'sub') If $min2 < $min Then $min = $min2 Else If $val < $min Then $min = $val EndIf Next Return $min EndFunc ;==>_GetMin Best Regards BugFix Link to comment Share on other sites More sharing options...
ericnail Posted November 23, 2010 Author Share Posted November 23, 2010 Than, i think, its better to use only one function to get min value from plain variables and/or 1D arrays. With recursive call it works fine: ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetMin ; Description ...: Gets min value from up to 10 single values and/or 1D-arrays ; Syntax.........: _GetMin($iStart, $n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) ; Parameters ....: $iStart start index from given arrays, if no arrays used you can set any (i.e. 0 or '') ; $n1...$n10 single values and/or 1D-arrays to get min value from ; Remarks .......: With arrays: all arrays using the same start index ; =============================================================================================================================== Func _GetMin($iStart, $n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) Local $min = $n1, $min2, $val If $n2 == 'sub' Then If UBound($n1) = $iStart +1 Then Return $n1[UBound($n1) -1] $min = $n1[$iStart] For $i = $iStart +1 To UBound($n1) -1 If $n1[$i] < $min Then $min = $n1[$i] Next Return $min EndIf If IsArray($min) Then $min = _GetMin($iStart, $min, 'sub') For $i = 2 To 10 $val = Eval('n' & $i) If IsKeyword($val) Then ExitLoop If IsArray($val) Then $min2 = _GetMin($iStart, $val, 'sub') If $min2 < $min Then $min = $min2 Else If $val < $min Then $min = $val EndIf Next Return $min EndFunc ;==>_GetMin The simple one here by bugfix works: Func _GetMin($n1, $n2, $n3=Default, $n4=Default, $n5=Default, $n6=Default, $n7=Default, $n8=Default, $n9=Default, $n10=Default) Local $min = $n1, $val For $i = 2 To 10 $val = Eval('n' & $i) If IsKeyword($val) Then ExitLoop If $val < $min Then $min = $val Next Return $min EndFunc However I found out that something is wrong w/ the _ArrayMinIndex function as it is never right :/ Thanks Guys! Link to comment Share on other sites More sharing options...
MvGulik Posted November 23, 2010 Share Posted November 23, 2010 (edited) However I found out that something is wrong w/ the _ArrayMinIndex function as it is never right :/Thats only a temporary problem that will probably solve itself after you have read the AutoIt documentation on array's, _ArrayMin and _ArrayMinIndex. Edited November 23, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... 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