Page 1 of 1

compare Array ?

Posted: Tue Oct 25, 2022 8:44 am
by AUGE_OHR
hi,

i do have 2 x Array from DIRECTORY()

how can i (quick) "compare" if they same :?:

Re: compare Array ?

Posted: Tue Oct 25, 2022 9:04 am
by gfilatov
AUGE_OHR wrote: Tue Oct 25, 2022 8:44 am hi,

i do have 2 x Array from DIRECTORY()

how can i (quick) "compare" if they same :?:
Hi Jimmy,

Please take a look at the following function which is included in the Minigui core: :arrow:

Code: Select all

*-----------------------------------------------------------------------------*
FUNCTION HMG_IsEqualArr ( aData1 , aData2 )
*-----------------------------------------------------------------------------*
   LOCAL x
   LOCAL lEqual := .T.

   IF Len ( aData1 ) == Len ( aData2 )

      FOR x := 1 TO Len ( aData1 )

         IF ValType ( aData1 [x] ) == ValType ( aData2 [x] )

            IF ISARRAY ( aData1 [x] )

               lEqual := HMG_IsEqualArr ( aData1 [x], aData2 [x] )

            ELSE

               IF aData1 [x] <> aData2 [x]

                  lEqual := .F.
                  EXIT

               ENDIF

            ENDIF

         ELSE

            lEqual := .F.
            EXIT

         ENDIF

      NEXT x

   ELSE

      lEqual := .F.

   ENDIF

RETURN lEqual
Hope that give you some idea :idea:

Re: compare Array ?

Posted: Tue Oct 25, 2022 9:20 am
by serge_girard
Nice recursive sample !

Re: compare Array ?

Posted: Tue Oct 25, 2022 1:04 pm
by edk
Thx Grigory.
I would change the line

Code: Select all

lEqual := HMG_IsEqualArr ( aData1 [x], aData2 [x] )
to

Code: Select all

IF .Not. HMG_IsEqualArr ( aData1 [x], aData2 [x] )
	Return .F.
ENDIF
It seems to me that in this case there is no point in investigating the matrix further.