Jump to content

Matching arrays, help!


Guy
 Share

Recommended Posts

Hi

This code will check if one 'one dimensional' array exists within the other. ie (if each number is an array element) it will check wether 456 exists in 123456789, witch it does and thus returns the value 6.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Dim $arra[$z][$z1]
Dim $arrb[$y][$y1]
;;; Set array elements here
$c = 0
$c1 = 0
$d = 0
$d1 = 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Do
$f = $c
If $arra[$c][$c1] = $arrb[$d][$d1] Then
       Do
               If $arra[$c][$c1] = $arrb[$d][$d1] Then
                      $d = $d + 1
                      $C = $C + 1
               Else
                      $c = $f +1
                      $d = 0
               EndIf
       Until $c = $z OR $d = 0 OR $d = $y
Else
       $c = $c + 1
EndIf
Until $c = $z OR $d  = $y
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If $d  = $y
    msgbox(0,"", "match at " & $c)
Else
   msgbox(0,"", "no match")
EndIf
$arra = 0
$arrb = 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Im trying to expand it so it will check 2 dimensional arrays but keep confusing myself.

can anyone help?

thanks

Guy

Link to comment
Share on other sites

I can think of a much easier way

For the one directional array.....

Convert the "1234567890" element array into a string. Then use StringInStr() function to search for "1234"

For the multidimentional array.....

Are you trying to find a 2D array inside of a larger 2D array?

Convert each row of the two dimentional array into strings. Then use StringInStr to find the first row of the smaller 2d array.

Then start searching for the rest of the rows from the same x location of the first one you find. If the next row doesn't match then start searching for the first row of the smaller 2d array from the row following the first found one......hope that makes sense.

looks like you're fairly proficient in autoit code, so I'll let you take care of the details :whistle: doing it the way I described above uses less code than you provided. B)

[quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...