Comparing structure variables with one command

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Comparing structure variables with one command

Post by marcoagpinto »

Heya,

I asked ChatGPT and he gave me this code:

Code: Select all

Structure Person
  Name.s
  Age.i
  Height.f
EndStructure

Dim Person1.Person(1)
Dim Person2.Person(1)

Person1(0)\Name = "John"
Person1(0)\Age = 25
Person1(0)\Height = 1.80

Person2(0)\Name = "John"
Person2(0)\Age = 25
Person2(0)\Height = 1.80

; Comparing the memory size of the two structures
If CompareMemory(@Person1(0), @Person2(0), SizeOf(Person))
  Debug "Structures are equal"
Else
  Debug "Structures are different"
EndIf
But I executed it, and it says that the structures are different.

Is there an easy way of doing this?

Thanks!
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Comparing structure variables with one command

Post by Fred »

What about CompareStructure() ?
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Comparing structure variables with one command

Post by marcoagpinto »

Fred wrote: Tue Oct 08, 2024 10:17 am What about CompareStructure() ?
Fred!!!

And how do I copy from one structured variable to the other with just 1 command (copy old to new or new to old values in the structured vars)?

Thank you, my good friend!
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Comparing structure variables with one command

Post by marcoagpinto »

Fred wrote: Tue Oct 08, 2024 10:17 am What about CompareStructure() ?
Fred!!!

Code: Select all

If CompareStructure(@Person1(0), @Person2(0))
If I press F1 for help in the command, it opens a blank page.
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Comparing structure variables with one command

Post by Fred »

Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Comparing structure variables with one command

Post by Fred »

You can just affect structure to copy: Person1(0) =Person2(0)
User avatar
marcoagpinto
Addict
Addict
Posts: 1076
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: Comparing structure variables with one command

Post by marcoagpinto »

Thanks, Fred!

After I recover from my stress, I will test it.

:oops: :oops: :oops: :oops: :oops: :oops:
Post Reply