Page 1 of 1

Comparing structure variables with one command

Posted: Tue Oct 08, 2024 10:15 am
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!

Re: Comparing structure variables with one command

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

Re: Comparing structure variables with one command

Posted: Tue Oct 08, 2024 10:20 am
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!

Re: Comparing structure variables with one command

Posted: Tue Oct 08, 2024 10:31 am
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.

Re: Comparing structure variables with one command

Posted: Tue Oct 08, 2024 10:35 am
by Fred

Re: Comparing structure variables with one command

Posted: Tue Oct 08, 2024 10:36 am
by Fred
You can just affect structure to copy: Person1(0) =Person2(0)

Re: Comparing structure variables with one command

Posted: Tue Oct 08, 2024 10:47 am
by marcoagpinto
Thanks, Fred!

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

:oops: :oops: :oops: :oops: :oops: :oops: