BlazerV60

Search an array for duplicates?

18 posts in this topic

Hello everyone :),

Let's say I have an array that contains these numbers: 2,5,7,2,25,6,31,1,24,5,7,8,7,99

How would I make my program be able to tell me something like "There are three 7's".

Is it possible to make an array detect duplicates and notify you?

Thanks,

Brian

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The _ArrayFindAll() UDF can be used to do this for you.

edit:

Here's an example:

#include <Array.au3>

Local $aArray[14] = [2,5,7,2,25,6,31,1,24,5,7,8,7,99]
Local $aResult = _ArrayFindAll($aArray, 7)
ConsoleWrite("There are " & UBound($aResult) & " 7's"& @LF)
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Perfect, thanks :D

Share this post


Link to post
Share on other sites

You bet. Good luck with your project. :)


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#Include <Array.au3>

Local $aArray[14] = [2,5,7,2,25,6,31,1,24,5,7,8,7,99]

For $i = ubound($aArray) - 1 to 0 step -1
Local $aResult = _ArrayFindAll($aArray, $aArray[$i])
if ubound($aResult) > 1 Then
msgbox (0 , '' , "There are " & ubound($aResult) & ":  " & $aArray[$i])
for $x = UBound($aResult) - 1 to 0 step - 1
    _ArrayDelete($aArray , $aResult[$x])
Next
Endif
$i = $i - (UBound($aResult) - 1)
Next

Edited by boththose
1 person likes this

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

a little improvement
this searches any duplicate (no need to know prior what to search)
note: if there are more empty elements are considered duplicate

#include <Array.au3>

Local $aArray[14] = [2,5,7,2,25,6,31,1,24,5,7,8,7,99]
Local $aResult
Local $aArrayUnique = _ArrayUnique($aArray, 1, 0, 0, 0) ; keep only single elements
If UBound($aArrayUnique) = UBound($aArray) Then
    ConsoleWrite("There are not duplicates." & @CRLF)
Else
    For $i = 0 To UBound($aArrayUnique) - 1
        $aResult = _ArrayFindAll($aArray, $aArrayUnique[$i])
        If UBound($aResult) > 1 Then
            ConsoleWrite("There are " & UBound($aResult) & " '" & $aArrayUnique[$i] & "'" & @LF)
        EndIf
    Next
EndIf

edit:

I saw the post by boththose only after I posted this
Edited by Chimp
1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
7 minutes ago, jguinch said:

Oups, sorry, it's not the good post...

@Chimp, your code does not work (seems to be an error with _ArrayUnique

 

Yes, cause of the second parameter of _ArrayUnique() that now is 0 based, while in previous versions it was 1 based.

Updated working code:

#include <Array.au3>

Local $aArray[14] = [2,5,7,2,25,6,31,1,24,5,7,8,7,99]
Local $aResult
Local $aArrayUnique = _ArrayUnique($aArray, 0, 0, 0, 0) ; keep only single elements
_ArrayDisplay($aArrayUnique)
If UBound($aArrayUnique) = UBound($aArray) Then
    ConsoleWrite("There are not duplicates." & @CRLF)
Else
    For $i = 0 To UBound($aArrayUnique) - 1
        $aResult = _ArrayFindAll($aArray, $aArrayUnique[$i])
        If UBound($aResult) > 1 Then
            ConsoleWrite("There are " & UBound($aResult) & " '" & $aArrayUnique[$i] & "'" & @LF)
        EndIf
    Next
EndIf

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
On 3/26/2016 at 8:39 PM, Chimp said:

Yes, cause of the second parameter of _ArrayUnique() that now is 0 based, while in previous versions it was 1 based.

Updated working code:

#include <Array.au3>

Local $aArray[14] = [2,5,7,2,25,6,31,1,24,5,7,8,7,99]
Local $aResult
Local $aArrayUnique = _ArrayUnique($aArray, 0, 0, 0, 0) ; keep only single elements
_ArrayDisplay($aArrayUnique)
If UBound($aArrayUnique) = UBound($aArray) Then
    ConsoleWrite("There are not duplicates." & @CRLF)
Else
    For $i = 0 To UBound($aArrayUnique) - 1
        $aResult = _ArrayFindAll($aArray, $aArrayUnique[$i])
        If UBound($aResult) > 1 Then
            ConsoleWrite("There are " & UBound($aResult) & " '" & $aArrayUnique[$i] & "'" & @LF)
        EndIf
    Next
EndIf

 

Hi sorry to open an older thread, it my first post and stuck. @Chimp I am using the above which is close to working for me.

 

What I have is an array with one column that has usernames and the other column passwords. What I want this script to do is list usernames who share the same password, so to count the column2 and display it. I can get the above working if it is on column1 it displays and counts usernames that are duplicates fine. If I change it to do this on column 2 it detects there is duplicates, but I cant get it to count or display them. I am sure if is something simple,but I just cant get this working and would really appreciate some help.

Here is an example of my data that is split into 2 columns in an array

 

user1: 76560BB696114467
user2: 76560BB696114467
user3: 76560BB696114467
user4: 76560BB696114467
user5: 76560BB696114467
user6: 765454545454545
user7: 7666565656565656
user8: 76560BB6uyuyu567
user1: 76560BB696114467

The array where this data sits is called avIPS.

Local $aResult
Local $aArrayUnique = _ArrayUnique($avIPs, 0, 0, 0, 0) ; keep only single elements
;_ArrayDisplay($aArrayUnique)

If UBound($aArrayUnique) = UBound($avIPs) Then
    ConsoleWrite("There are not duplicates." & @CRLF)

Else
    ConsoleWrite("There are duplicates." & @CRLF)
    For $i = 0 To UBound($aArrayUnique) - 1
       $aResult = _ArrayFindAll($avIPs, $aArrayUnique[$i])
        If UBound($aResult) > 1 Then
            ConsoleWrite("There are " & UBound($aResult) & " '" & $aArrayUnique[$i] & "'" & @LF)
        EndIf
    Next
EndIf

So running the above on my array on matches column1 fine and says there are 2 user1 which is correct

There are duplicates.
There are 2 'user1'

If I alter the above to try and work on the password column (changing 0,0,0,0 to 1,0,0,0 ) then it detects there are duplicates but doesnt count or display them, so is something I need to edit around the Ubound I think?

 

Local $aResult
Local $aArrayUnique = _ArrayUnique($avIPs, 1, 0, 0, 0) ; keep only single elements
;_ArrayDisplay($aArrayUnique)

If UBound($aArrayUnique) = UBound($avIPs) Then
    ConsoleWrite("There are not duplicates." & @CRLF)

Else
    ConsoleWrite("There are duplicates." & @CRLF)
    For $i = 0 To UBound($aArrayUnique) - 1
       $aResult = _ArrayFindAll($avIPs, $aArrayUnique[$i])
        ;If UBound($aResult) > 1 Then
            ConsoleWrite("There are " & UBound($aResult) & " '" & $aArrayUnique[$i] & "'" & @LF)
       ; EndIf
    Next
EndIf

This is then my output, so it knows there are duplicates, but wont count them.

 

There are duplicates.
There are 1 ''
There are 0 ' 76560BB696114467'
There are 0 ' 765454545454545'
There are 0 ' 7666565656565656'
There are 0 ' 76560BB6uyuyu567'

Worst case I would like it to say there are 5x users with password 76560BB696114467 or even better the following usernames have the same password of 76560BB696114467.

This are not real passwords, just an example.

 

Any pointers I would be really grateful. thanks

 

Share this post


Link to post
Share on other sites
#include <Array.au3>
local $aFinal[0]

Local $avArray[9][2] = [ _
        ["user1", "76560BB696114467"], _
        ["user2", "76560BB696114467"], _
        ["user3", "76560BB696114467"], _
        ["user4", "76560BB696114467"], _
        ["user5", "76560BB696114467"], _
        ["user6", "765454545454545"], _
        ["user7", "7666565656565656"], _
        ["user8", "76560BB6uyuyu567"], _
        ["user1", "76560BB696114467"]]


 $aUniquePW = _ArrayUnique($avArray , 1)

For $i = 1 to ubound($aUniquePW) - 1

   $aMatch = _ArrayFindAll($avArray , $aUniquePW[$i] , 0 , 0 , 0 , 0 , 1)

      for $k = 0 to ubound($aMatch) - 1
         $aMatch[$k] = $avArray[$aMatch[$k]][0]
      next

      $aUniqueUser = _ArrayUnique($aMatch)
      $aUniqueUser[0] = $aUniquePW[$i]
      _ArrayAdd($aUniqueUser , "")
      _ArrayConcatenate($aFinal , $aUniqueUser)

Next

_ArrayDisplay($aFinal)

 

1 person likes this

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
16 minutes ago, iamtheky said:
#include <Array.au3>
local $aFinal[0]

Local $avArray[9][2] = [ _
        ["user1", "76560BB696114467"], _
        ["user2", "76560BB696114467"], _
        ["user3", "76560BB696114467"], _
        ["user4", "76560BB696114467"], _
        ["user5", "76560BB696114467"], _
        ["user6", "765454545454545"], _
        ["user7", "7666565656565656"], _
        ["user8", "76560BB6uyuyu567"], _
        ["user1", "76560BB696114467"]]


 $aUniquePW = _ArrayUnique($avArray , 1)

For $i = 1 to ubound($aUniquePW) - 1

   $aMatch = _ArrayFindAll($avArray , $aUniquePW[$i] , 0 , 0 , 0 , 0 , 1)

      for $k = 0 to ubound($aMatch) - 1
         $aMatch[$k] = $avArray[$aMatch[$k]][0]
      next

      $aUniqueUser = _ArrayUnique($aMatch)
      $aUniqueUser[0] = $aUniquePW[$i]
      _ArrayAdd($aUniqueUser , "")
      _ArrayConcatenate($aFinal , $aUniqueUser)

Next

_ArrayDisplay($aFinal)

 

Perfect thanks very much, works just as I wanted.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Sorry to be a pain @iamtheky what would the easiest way using your example to only show usernames/passwords where greater than 1? i.e only display the items in the array if more than 1 user shares the same password. Basically I am only interested in if users have the same password as others.

 

many thanks

Edited by Dizzastaffy

Share this post


Link to post
Share on other sites

check $aUniqueUser[0] > 1

Do that right after its created, and If true then proceed on to change the value in element 0 to the password, add the blank row, and concatenate with final, else continueloop.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
18 minutes ago, iamtheky said:

check $aUniqueUser[0] > 1

Do that right after its created, and If true then proceed on to change the value in element 0 to the password, add the blank row, and concatenate with final, else continueloop.

Thanks. So if I understand correct you mean add a if $aUniqueUser[0] > 1 then after this line

or do you mean after the end of the script and array afinal is created?

    $aUniqueUser = _ArrayUnique($aMatch)

Share this post


Link to post
Share on other sites

yeah, you can put an _ArrayDisplay($aUniqueUser) line there as well to debug if there are issues or edge cases unaccounted for.

1 person likes this

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

You can also view users that share passwords groupped in a treeview...

#include <Array.au3>
#include <TreeViewConstants.au3>
#include <GUITreeView.au3>
#include <WindowsConstants.au3>

Local $aArray = [ _
        ["user1", "76560BB696114467"], _
        ["user2", "76560BB696114467"], _
        ["user3", "76560BB696114467"], _
        ["user4", "76560BB696114467"], _
        ["user5", "76560BB696114467"], _
        ["user6", "76560BB6uyuyu567"], _
        ["user7", "765454545454545"], _
        ["user8", "76560BB6uyuyu567"], _
        ["user9", "765454545454545"]]

Local $aResult, $aArrayUnique = _ArrayUnique($aArray, 1, 0, 1, 0) ; keep only single elements
If UBound($aArrayUnique) = UBound($aArray) Then
    MsgBox(0, "Info", "There are not duplicates.")
Else
    $hMain = GUICreate("unwary users", 280, 400, 10, 10)
    $hTree = GUICtrlCreateTreeView(5, 5, 270, 390, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    GUISetState()
    _GUICtrlTreeView_BeginUpdate($hTree)
    Local $hAncestor = _GUICtrlTreeView_Add($hTree, 0, "Shared pwds")
    For $i = 0 To UBound($aArrayUnique) - 1
        $aResult = _ArrayFindAll($aArray, $aArrayUnique[$i], 0, 0, 0, 0, 1) ; password
        If UBound($aResult) > 1 Then
            Local $hGroup = _GUICtrlTreeView_AddChild($hTree, $hAncestor, $aArray[$aResult[0]][1])
            For $i1 = 0 To UBound($aResult) - 1
                _GUICtrlTreeView_AddChild($hTree, $hGroup, $aArray[$aResult[$i1]][0]) ; Users
            Next
        EndIf
    Next
    _GUICtrlTreeView_EndUpdate($hTree)
    MsgBox(0, "Pause", "Click OK to end")
EndIf

 

Edited by Chimp
debugged listing
1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

There it is new folk.  Give all the details, show effort, get multiple responses that solve the problem. That's how this biatch works.  

No one even harassed him for resjacking (which i just coined and should be used everywhere) a thread, because its related, and a complete question.

1 person likes this

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Thanks all. There has been many times I wanted to post, but got there in the end by looking, trying, more trying and looking at other answers on the forum. I have gone from never using to writing something that is very useful. I didn't want to just post hi how do I do this without even trying, I tried but was above my knowledge in this case, I have several arrays working by reading files, splitting data, etc, but this one got me. thanks 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • rootx
      By rootx
      I write this script to compare to array, well Do you have a better way to do it?
      #include <Constants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $a = FileSelectFolder("seleziona cartella A",@ScriptDir) $fold_A = _FileListToArrayRec($a,"*",2,1,0,1) $b = FileSelectFolder("seleziona cartella B",@ScriptDir) $fold_B = _FileListToArrayRec($b,"*",2,1,0,1) $tota = UBound($fold_A)-1 $totb = UBound($fold_B)-1 If $tota > $totb Then findx($fold_A,$fold_B) Else findx($fold_B,$fold_A) EndIf Func findx($min,$max) For $i = 0 To UBound($min)-1 $found = _ArraySearch($max, $min[$i]) If $found = -1 Then ConsoleWrite($min[$i]&@CRLF) EndIf Next EndFunc  
    • Jibberish
      By Jibberish
      I am trying to add data to an array and I keep getting the error "Subscript used on non-accessible variable ".
      #include <array.au3> ; Includes, etc ~ ~ ~ Local $aOptionsArray[3] $aOptionsArray = CheckboxesAndRadioButtons() _ArrayDisplay($aOptionsArray) Func CheckboxesAndRadioButtons() ; Create Checkboxes and Radio Buttons and read the results ~ ~ ~ ; Radio Buttons to Array ; $aOptions[0] = $bTestSelectForever ; $aOptions[1] = $bTestSelect3Times ; $aOptions[2] = $bTestSelectOnce If $bSelect1 = 1 Then $aOptions[0] = "True" Else $aOptions[0] = "False" <<< This is where the error occurs. EndIf If $bSelect2 = 1 Then $aOptions[1] = "True" Else $aOptions[1] = "False" EndIf If $bSelect3 = 1 Then $aOptions[2] = "True" Else $aOptions[2] = "False" EndIf Return $aOptions EndFunc Is putting data into an array while in a If - Then - Else illegal?
    • anoig
      By anoig
      Hi all, 

      First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

      I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

      The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

      So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

      Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.
      -Anoig
       
    • InunoTaishou
      By InunoTaishou
      Cleaning up some old folders and found this little snippit. Think I was using this back when I was trying to create 2d maps for a game I was making in GDI+ (that never got finished). Pretty straight forward, searches an array for an array.
      #include <Array.Au3> Search() Func Search() Local $aArrayToFind[][] = [["V", "V", "V", "V", "V"], ["V", "V", "V", "V", "V"], ["V", "V", "V", "V", "B"], ["V", "V", "V", "V", "B"], ["V", "V", "V", "V", "B"]] Local $aArrayToSearch[][] = [["R", "R", "R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "V", "V", "V", "V", "V", "T", "T", "T", "T", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "B", "B", "B", "B", "B", "B", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "B", "B", "B", "B", "B", "B", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "X", "V", "V", "V", "X", "B", "B", "B", "B", "B", "V", "V", "V", "V", "B", "B", "B", "B", "B", "B", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "B", "B", "B", "B", "B", "V", "V", "V", "X", "V", "V", "B", "D", "B", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "X", "V", "V", "V", "X", "B", "D", "B", "B", "B", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "V", "V", "V", "X", "X", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "R", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "V", "V", "V", "X", "T", "T", "T", "T", "T", "T", "T", "T", "X", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "T", "T", "T", "T", "T", "T"], _ ["V", "V", "V", "V", "V", "V", "V", "V", "V", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "V", "X", "V", "V", "X", "B", "B", "B", "B", "B", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "B", "B", "B", "B", "B", "V", "V", "V", "V", "V", "M", "M", "M", "M", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "X", "B", "D", "B", "B", "B", "V", "V", "V", "V", "V", "M", "M", "M", "M", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "M", "M", "D", "M", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "C", "C", "C", "C", "C", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "V", "T", "T", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "C", "C", "C", "C", "C", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "T", "T", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "C", "C", "C", "C", "C", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "W", "W", "W", "W", "W", "W", "V", "V", "V", "V", "V", "V", "V", "C", "C", "D", "C", "C", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "W", "W", "W", "W", "W", "W", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "W", "W", "W", "W", "W", "W", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "W", "W", "W", "W", "W", "W", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "L", "L", "L", "L", "W", "W", "W", "W", "W", "W", "L", "L", "L", "V", "V", "V", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "X", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "R", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"], _ ["R", "R", "R", "R", "R", "R", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "V", "V", "V", "V", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T", "T"]] Local $aArrayInArray = ArrayInArray($aArrayToSearch, $aArrayToFind) If (@Error) Then MsgBox("", "Error", "Error doing search: " & @Error) Else If ($aArrayInArray[0] = 1) Then ToolTip("Start Coords = " & $aArrayInArray[1] & ", " & $aArrayInArray[2] & @LF & _ "End Coords = " & $aArrayInArray[1] + UBound($aArrayToFind, $UBOUND_ROWS) - 1 & ", " & $aArrayInArray[2] + UBound($aArrayToFind, $UBOUND_COLUMNS) - 1 & @LF & _ "(Approx) Center coords = " & $aArrayInArray[1] + Int(UBound($aArrayToFind, $UBOUND_ROWS) / 2) & ", " & $aArrayInArray[2] + Int(UBound($aArrayToFind, $UBOUND_COLUMNS) / 2), 0, 0) $aArrayToSearch[$aArrayInArray[1]][$aArrayInArray[2]] = "Start" $aArrayToSearch[$aArrayInArray[1] + UBound($aArrayToFind, $UBOUND_ROWS) - 1][$aArrayInArray[2] + UBound($aArrayToFind, $UBOUND_COLUMNS) - 1] = "End" $aArrayToSearch[$aArrayInArray[1] + Int(UBound($aArrayToFind, $UBOUND_ROWS) / 2)][$aArrayInArray[2] + Int(UBound($aArrayToFind, $UBOUND_COLUMNS) / 2)] = "(Approx) Center" _ArrayDisplay($aArrayToSearch, "ArrayInArray") ElseIf ($aArrayInArray[0] > 1) Then MsgBox("", "Multiple Matches", "Multiple Matches Found For Search") Else MsgBox("", "No Matches", "No Matches Found For Search") EndIf EndIf EndFunc ;==>Start Func ArrayInArray($aArrayToSearch, $aArrayToFind) Local $aReturn[3] = [0, -1, -1] If (Not IsArray($aArrayToSearch)) Then Return SetError(1, 0, $aReturn) If (Not IsArray($aArrayToFind)) Then Return SetError(2, 0, $aReturn) Local $iRowsToSearch = UBound($aArrayToSearch, $UBOUND_ROWS) Local $iColumnsToSearch = UBound($aArrayToSearch, $UBOUND_COLUMNS) Local $iRowsToFind = UBound($aArrayToFind, $UBOUND_ROWS) Local $iColumnsToFind = UBound($aArrayToFind, $UBOUND_COLUMNS) If ($iRowsToFind > $iRowsToSearch) Then Return SetError(3, 0, $aReturn) If ($iColumnsToFind > $iColumnsToSearch) Then Return SetError(4, 0, $aReturn) For $iRow = 0 To $iRowsToSearch - $iRowsToFind For $iColumn = 0 To $iColumnsToSearch - $iColumnsToFind Local $bValid = False For $i = 0 To $iRowsToFind - 1 For $p = 0 To $iColumnsToFind - 1 If ($aArrayToFind[$i][$p] = "" Or $aArrayToFind[$i][$p] = $aArrayToSearch[$iRow + $i][$iColumn + $p]) Then $bValid = True Else $bValid = False ExitLoop 2 EndIf Next Next If ($bValid) Then ; Number of valid results found $aReturn[0] += 1 ; row of the last valid result found $aReturn[1] = $iRow ; column of the last valid result found $aReturn[2] = $iColumn EndIf Next Next Return $aReturn EndFunc ;==>ArrayInArray ArrayInArray Returns an array: [0] = number of results found, [1] = row of the last valid result found, [2] = column of the last valid result found
    • distancesprinter
      By distancesprinter
      _ArrayDisplay($aArray, "Window Title", "1:", 0, Default, "Column") ; Expected results are rows 1 to the end of the array, all columns. The result is rows 0-1, all columns. The API reference is here:
      https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayDisplay.htm
       
      Am I doing something wrong?