Copia e comparazione array e strutture dati – Support Elsist https://support.elsist.biz/forums/topic/copia-e-comparazione-array-e-strutture-dati/feed/ Fri, 30 Oct 2026 08:12:39 +0000 https://bbpress.org/?v=2.6.20 it-IT https://support.elsist.biz/forums/topic/copia-e-comparazione-array-e-strutture-dati/#post-82231 Copia e comparazione array e strutture dati https://support.elsist.biz/forums/topic/copia-e-comparazione-array-e-strutture-dati/#post-82231 Thu, 15 May 2025 08:26:27 +0000 Anonimo La copia di una variabile array in un’altra funziona mentre se eseguo il confronto tra due variabili array ho errore in compilazione.

VAR
    ChkOk : BOOL;
    MyArray1 : ARRAY[0..7] OF BYTE := [1, 2, 3, 4, 5, 6 ,7, 8];
    MyArray2 : ARRAY[0..7] OF BYTE;
END_VAR

    MyArray2:=MyArray1;
    ChkOk:=TO_BOOL(MyArray1 = MyArray2);

TestArray(3) - error A4136:  MyArray1 => Missing index(es)
TestArray(3) - error A4136:  MyArray2 => Missing index(es)

Ho provato ad eseguire la stessa operazione su strutture dati ed anche in questo caso ho un errore in compilazione.

VAR
    ChkOk : BOOL;
    MyStruct1 : MYSTRUCT := (MyVar1:=TRUE, MyVar2:=FALSE, MyVar3:=TRUE);
    MyStruct2 : MYSTRUCT;
END_VAR

    MyStruct2:=MyStruct1;
    ChkOk:=TO_BOOL(MyStruct1 = MyStruct2);

TestStruct(3) - error G0008:  LD => Invalid access to variable

Ho comesso qualche errore nei miei programmi oppure c’è un problema nella comparazione.

]]>
https://support.elsist.biz/forums/topic/copia-e-comparazione-array-e-strutture-dati/#post-82240 Rispondi a: Copia e comparazione array e strutture dati https://support.elsist.biz/forums/topic/copia-e-comparazione-array-e-strutture-dati/#post-82240 Thu, 15 May 2025 08:42:19 +0000 Sergio Bertana In effetti LogicLab permette di definire la copia di variabili sia di tipo array che di tipo struttura, ma non permette operazioni di confronto.

Nelle nostre librerie è disponibile la funzione MemCompare che oltre ad eseguire la comparazione tra qualsiasi tipo di variabile se il parametro Update è attivo esegue anche la copia del valore della variabile definita in Source nella variabile definita in Destination.

Quindi il tuo programma diventerà:

VAR
    ChkOk : BOOL;
    MyStruct1 : MYSTRUCT;
    MyStruct2 : MYSTRUCT;
END_VAR

    MyStruct2:=MyStruct1;
    ChkOk:=NOT(MemCompare(ADR(MyStruct2), ADR(MyStruct1), SIZEOF(MyStruct2), FALSE));
]]>