#include #include ; Search all elements of Array $aFindThis in 2nd Array $aData ; ; if both arrays are really large, it speeds up the procedure to ; 1.) sort both of them ; 2.) save the old position of "data" in a 2nd column ; 3.) monitor, when in the 2nd Array the position is reached, where no further occurrences *CAN* show up (due to sorting), then "continueloop 2" ; 4.) $OldStart will save the correct start in the case, the 1st array should have duplicate values $DataFile = @TempDir & "\SomeDummyData.txt" ; create some random numbers between 1 and 100 Dim $aRawData[10001]=[10000] For $i = 1 To 10000 $aRawData[$i]=Random(1, 100, 1) Next ; dump these raw random data to an array _FileWriteFromArray($DataFile, $aRawData,1) ; transfer these data to an 2D array, so that the old position can be preseved on the 2nd column Dim $aData[UBound($aRawData)][2] = [[$aRawData[0], "Position"]] For $i = 1 To $aRawData[0] $aData[$i][0] = $aRawData[$i] $aData[$i][1] = $i Next _ArrayDisplay($aData, "Col 0: Data, Col 1: Line Number") _ArraySort($aData, 0, 1) _ArrayDisplay($aData, "Col 0: sorted, Col 1: Old Position") $NotFound = "not found so far" Dim $aFindThis[5][2] = [[4]] For $i = 1 To $aFindThis[0][0] $aFindThis[$i][0] = Random(1, 100, 1) $aFindThis[$i][1] = $NotFound Next $aFindThis[2][0] = $aFindThis[4][0] ;artifically force a "duplicate value" _ArraySort($aFindThis, 0, 1) _ArrayDisplay($aFindThis, "We are going to search for these values:") $Start = 1 $OldStart = 1 For $i = 1 To $aFindThis[0][0] If ($i > 1) And ($aFindThis[$i][0] = $aFindThis[$i - 1][0]) Then $Start = $OldStart Else $OldStart = $Start EndIf For $x = $Start To $aData[0][0] If $aFindThis[$i][0] < $aData[$x][0] Then $Start = $x ContinueLoop 2 EndIf If $aFindThis[$i][0] = $aData[$x][0] Then If $aFindThis[$i][1] = $NotFound Then $aFindThis[$i][1] = $aData[$x][1] Else $aFindThis[$i][1] &= "|" & $aData[$x][1] EndIf EndIf Next Next For $i = 1 To $aFindThis[0][0] If $aFindThis[$i][1] = $NotFound Then MsgBox(0, $aFindThis[$i][0], "Value didn't occur.") Else $foo = StringSplit($aFindThis[$i][1], "|") _ArraySortNum($foo, 1, 1) $foo[0] = $foo[0] & " occurrences" _ArrayDisplay($foo, "Result: Value '" & $aFindThis[$i][0] & "' found. There are " & $foo[0] & " at these positions:") EndIf Next Func _ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1) ; By SmOke_N to be found here: https://www.autoitscript.com/wiki/Snippets_%28_AutoIt_Array_%29#ArraySortNum ; Note: to do an ascending sort set $Ascending = 1 For $i = $Start To UBound($nArray) - 2 Local $SE = $i If $Ascending = 0 Then For $x = $i To UBound($nArray) - 1 If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x Next Else For $x = $i To UBound($nArray) - 1 If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x Next EndIf Local $HLD = $nArray[$i] $nArray[$i] = $nArray[$SE] $nArray[$SE] = $HLD Next EndFunc ;==>_ArraySortNum