Is there any way to use the elements in the struct via index?
It means using
DataRead[1] := 0 instead of DataRead.Data1 := 0,
DataRead[2] := 0 instead of DateRead.Data2 := 0, etc.
Thanks.
Last edit: stade 2020-06-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Actually I have hundreds of elements with different datatype in the struct, which means there are Data1 .. Data1000(or more).
The names of element are illustrative, actually they are irregular.
I have only 1 DataExchange named DataRead, and I want to use index as parameter to call the element I need.
For example, when I want to call Data50, I may use index 50 to call this element, instead of using DataRead.Data50.
But I have no idea how to implement it.
Sorry for my bad statement and thanks for your answer.
Last edit: stade 2020-06-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are (from what I understand) trying to describe an array of pointers to your elements instances but i have difficulties in understanding your writing, so I could misinterpret it.
It looks like every DataExchangeN in your code means different DataExchange.
I have only 1 DataExchange and hundreds of variables with different datatype in this DataExchange.
So what I want is likely
Collection[0] point to DataRead.Data1,
Collection[1] point to DataRead.Data2,
..
Collection[N] point to DataRead.DataN+1.
I will try if pointer can do this, thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I have a struct with elements in different datatype, for example:
TYPE DataExchange :
STRUCT
Data1 : INT;
Data2 : WORD;
Data3 : DWORD;
END_STRUCT
END_TYPE
VAR
DataRead : DataExchange;
END_VAR
Is there any way to use the elements in the struct via index?
It means using
DataRead[1] := 0 instead of DataRead.Data1 := 0,
DataRead[2] := 0 instead of DateRead.Data2 := 0, etc.
Thanks.
Last edit: stade 2020-06-22
Structs are NOT Types!
Apparently you want a Struct of your own type which is achieved like this:
Usage
Offcourse 0..31 and a,b,c,x,y,z are illustrative.
Regards,
Aliazzz
Last edit: aliazzz 2020-06-22
Hi aliazzz.
Actually I have hundreds of elements with different datatype in the struct, which means there are Data1 .. Data1000(or more).
The names of element are illustrative, actually they are irregular.
I have only 1 DataExchange named DataRead, and I want to use index as parameter to call the element I need.
For example, when I want to call Data50, I may use index 50 to call this element, instead of using DataRead.Data50.
But I have no idea how to implement it.
Sorry for my bad statement and thanks for your answer.
Last edit: stade 2020-06-22
You are (from what I understand) trying to describe an array of pointers to your elements instances but i have difficulties in understanding your writing, so I could misinterpret it.
Good luck!
Last edit: aliazzz 2020-06-22
It looks like every DataExchangeN in your code means different DataExchange.
I have only 1 DataExchange and hundreds of variables with different datatype in this DataExchange.
So what I want is likely
Collection[0] point to DataRead.Data1,
Collection[1] point to DataRead.Data2,
..
Collection[N] point to DataRead.DataN+1.
I will try if pointer can do this, thanks.
If you have cracked your problem, would you mind posting/sharing your solution here?
Thanks
Last edit: aliazzz 2020-06-23