rodiney Posted February 18, 2016 Share Posted February 18, 2016 (edited) hello need help with array, I'm using search array to find a number stored in this array. example: $ array [0] = 2 $ array [1] = 2 and I need to look for the number 2 within the array, I check the 2, 2 stored in the array, in my case it only finds the first array $ array [0] i need check two array. Script. #include <Array.au3> #include <MsgBoxConstants.au3> Local $avArray[2] $avArray[0] = 2 $avArray[1] = 2 _ArrayDisplay($avArray, "$avArray") Local $sSearch = 2 Local $iIndex = _ArraySearch($avArray, $sSearch, 0, 0, 0, 1, 1, 0) If @error Then MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $sSearch & '" was not found") Else MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex) EndIf Edited February 18, 2016 by rodiney Link to comment Share on other sites More sharing options...
czardas Posted February 18, 2016 Share Posted February 18, 2016 (edited) Is this any help? #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[4] = [2, 2, 0, 2] ; array to search Local $vSearchWhat = 2 Local $iIndex = -1, $iItems = 0, $aResults[UBound($aArray)] While 1 $iIndex = _ArraySearch($aArray, $vSearchWhat, $iIndex +1) If $iIndex <> -1 Then $aResults[$iItems] = $iIndex $iItems += 1 Else ExitLoop EndIf WEnd ReDim $aResults[$iItems] _ArrayDisplay($aResults) ; indeces ; additional code Local $sRet = "" If UBound($aResults) = 0 Then MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $vSearchWhat & '" was not found') Else For $i = 0 To UBound($aResults) -1 ; loop through the results $sRet &= $aResults[$i] & ", " Next $sRet = StringTrimRight($sRet, 2) MsgBox($MB_SYSTEMMODAL, "Found", '"' & $vSearchWhat & '" was found in the array at positions ' & $sRet) EndIf Edited February 18, 2016 by czardas additional code rodiney 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
rodiney Posted February 18, 2016 Author Share Posted February 18, 2016 4 hours ago, czardas said: Is this any help? #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[4] = [2, 2, 0, 2] ; array to search Local $vSearchWhat = 2 Local $iIndex = -1, $iItems = 0, $aResults[UBound($aArray)] While 1 $iIndex = _ArraySearch($aArray, $vSearchWhat, $iIndex +1) If $iIndex <> -1 Then $aResults[$iItems] = $iIndex $iItems += 1 Else ExitLoop EndIf WEnd ReDim $aResults[$iItems] _ArrayDisplay($aResults) ; indeces ; additional code Local $sRet = "" If UBound($aResults) = 0 Then MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $vSearchWhat & '" was not found') Else For $i = 0 To UBound($aResults) -1 ; loop through the results $sRet &= $aResults[$i] & ", " Next $sRet = StringTrimRight($sRet, 2) MsgBox($MB_SYSTEMMODAL, "Found", '"' & $vSearchWhat & '" was found in the array at positions ' & $sRet) EndIf I will test it. Thank you Link to comment Share on other sites More sharing options...
czardas Posted February 18, 2016 Share Posted February 18, 2016 (edited) Easier than the above : you could simply use _ArrayFindAll(). Check the help file. It's almost the same thing! Edited February 18, 2016 by czardas operator64 ArrayWorkshop 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