Jump to content
Sign in to follow this  
NileshSutar

comparing 2d arrays

Recommended Posts

NileshSutar

Hi guys,

i want to compare two "2D" arrays such that it should return 0 if no element is common and 1 if one or more elements are common.How can i do that.???

Share this post


Link to post
Share on other sites
FireFox

Hi,

Nested For.

Think in your head how you would do it and then translate it, quite easy.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
NileshSutar

i have done it> but the arrays come from different function.How can i import them in my compare function

Share this post


Link to post
Share on other sites
FireFox

Post your code, so we can see what you're talking about ;)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
water

Define both arrays by using Global to make them available for every function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chimp

Assuming both arrays has the same number of elements, something like this should work

Func Compare2D(ByRef $Array1, ByRef $Array2)

    Local $Check = 0

    For $x = 0 To UBound($Array1, 1) -1
        For $y = 0 To UBound($Array1, 2) -1
            $Check += ($Array1[$x][$y] = $Array2[$x][$y])
        Next
    Next

    $Check = $Check > 0

    Return $Check

EndFunc   ;==>Compare2D

(not tested)

bye

edit

added -1 to ubound in listing

Edited by PincoPanco

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
NileshSutar

Define both arrays by using Global to make them available for every function.

Worked

thanks

Share this post


Link to post
Share on other sites
AZJIO

First check that the dimensions of the array are the same.

Make "ExitLoop" out of the loop if the going does not match. I don't think that should be checked until the end, if the first cell is not the same.

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
Sign in to follow this  

×