gcue Posted March 26, 2010 Share Posted March 26, 2010 (edited) i have an array of numbers whats the most efficient way of comparing all of them to find the largest number? was trying to use a for loop for a faster/more efficient compare but cant figure out the logic For $x = 1 To 4 If $aINIs[$x][1] > $aINIs[$x + 1][1] Then $largest = $x Else $largest = $x + 1 EndIf Next msgbox(0,"", $largest & " is the largest") thanks =) Edited March 26, 2010 by gcue Link to comment Share on other sites More sharing options...
gcue Posted March 26, 2010 Author Share Posted March 26, 2010 nevermind _arraymaxindex! thanks =) Link to comment Share on other sites More sharing options...
gcue Posted March 26, 2010 Author Share Posted March 26, 2010 what can i use for a multicolumn array? doesnt seem that _arraymaxindex supports more than one column Link to comment Share on other sites More sharing options...
Spiff59 Posted March 26, 2010 Share Posted March 26, 2010 If you wanted to do it in the least lines of Autoit code, you could probably just use _ArraySort and then check the last (or first, depending upon sort order) element for your value. Of course, that method destroys the original order of your array, and behind the scenes is doing a ton more processing than is necessary. You were on the right track to begin with, with something like: $largest = 0 For $x = 1 To UBound($aINI, 1) - 1 If $aINIs[$x][1] > $aINIs[$x - 1][1] Then $largest = $x Next MsgBox(0,"", "Index " & $largest & " is the largest, with a value of: " & $aINIs[$largest][1]) Link to comment Share on other sites More sharing options...
gcue Posted March 26, 2010 Author Share Posted March 26, 2010 (edited) thanks for the response spiff that doesn't seem to be working properly though.. it says index 5 value is the largest when its not http://www.postimage.org/image.php?v=gxyZHBA Edited March 26, 2010 by gcue Link to comment Share on other sites More sharing options...
jchd Posted March 26, 2010 Share Posted March 26, 2010 (edited) $largest = 0 For $x = 0 To UBound($aINI, 1) - 1 If $aINIs[$x][1] > $largest Then $largest = $x Next MsgBox(0,"", "Index " & $largest & " is the largest, with a value of: " & $aINIs[$largest][1]) Oops,you're right, $largest needs going thru array indexing. Edited March 26, 2010 by jchd 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...
Spiff59 Posted March 26, 2010 Share Posted March 26, 2010 (edited) Pardon me, the Mark 1 Eyeball failed me. $largest = 0 For $x = 1 To UBound($aINIs, 1) - 1 If $aINIs[$x][1] > $aINIs[$largest][1] Then $largest = $x Next MsgBox(0,"", "Index " & $largest & " is the largest, with a value of: " & $aINIs[$largest][1]) Edited March 26, 2010 by Spiff59 Link to comment Share on other sites More sharing options...
gcue Posted March 26, 2010 Author Share Posted March 26, 2010 works great! thanks guys 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