compare Array ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

compare Array ?

Post by AUGE_OHR »

hi,

i do have 2 x Array from DIRECTORY()

how can i (quick) "compare" if they same :?:
have fun
Jimmy
User avatar
gfilatov
Posts: 1116
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: compare Array ?

Post 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:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
serge_girard
Posts: 3420
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: compare Array ?

Post by serge_girard »

Nice recursive sample !
There's nothing you can do that can't be done...
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: compare Array ?

Post 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.
Post Reply