Phaser Posted February 25, 2012 Share Posted February 25, 2012 (edited) I have an array that gets updated each time data in entered local $array[12]=[1,9,11,5,1,12,10,16,8,1,9,3] I need to know when when 4 of the elements have hit 10 or greater, so from the above I would like to be told that indexes 2,5,6,7 have met the criteria as there are 4 elements of 10 or greater. How do I perform a check each time data is entered to find the top 4 values? I can get my head around it. I will also be doing the same on the top 3 and top 2 but assume top 4 would be the strating point to understand it. Edited February 25, 2012 by Phaser Link to comment Share on other sites More sharing options...
water Posted February 25, 2012 Share Posted February 25, 2012 Do you just have to know the number of elements or the indices of the elements > 10? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Phaser Posted February 25, 2012 Author Share Posted February 25, 2012 No, I need to know that there are 4 of 10 or greater and the indices they are at, thats why I cant get my head around it Link to comment Share on other sites More sharing options...
water Posted February 25, 2012 Share Posted February 25, 2012 You would need something like this: #include <array.au3> Global $iLimit = 10 Global $iCount = 0 Global $aInput[12] = [1,9,11,5,1,12,10,16,8,1,9,3] Global $aIndices[UBound($aInput)] For $i = 0 To UBound($aInput)-1 If $aInput[$i] >= $iLimit Then For $j = 0 To $iCount If $aIndices[$j] = $aInput[$i] Then ContinueLoop If $aIndices[$j] = "" Then $aIndices[$j] = $aInput[$i] $iCount = $iCount + 1 ExitLoop EndIf Next Endif Next _ArrayDisplay($aIndices) ConsoleWrite("# of indices >= " & $iCount & @CRLF) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Phaser Posted February 25, 2012 Author Share Posted February 25, 2012 Many thanks water, I will see if I can work with that, thanks for your help Link to comment Share on other sites More sharing options...
Malkey Posted February 25, 2012 Share Posted February 25, 2012 Try this. Local $aInput[12] = [1, 9, 11, 5, 1, 12, 10, 16, 8, 1, 9, 3] Local $iLimit = 10 Local $iCount = 0 Local $sIndices = "" For $i = 0 To UBound($aInput) - 1 If $aInput[$i] >= $iLimit Then $iCount += 1 If $iCount <= 4 Then $sIndices &= $i & "," Else ExitLoop EndIf EndIf Next ConsoleWrite("The indices with values >= 10 are " & StringTrimRight($sIndices, 1) & "." & @CRLF) #cs Output is:- The indices with values >= 10 are 2,5,6,7. #ce 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