An explaination what is happening:
When you declare the array it is basically a custom variable type and the input to the function needs to match exactly that even though the second dimension would look the same as a one dimensional array uncompiled.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What's actually the difference between ARRAY [1..6,1..38] OF WORD, and ARRAY [1..6] OF ARRAY[1..38] OF WORD? It seems to me that they're the same thing. In either case arrRawData[1] should be an ARRAY [1..38] OF WORD. Other programming languages treat arrays in this way, is this just one of those Codesys quirks?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not sure but :
If you use ARRAY [1..6,1..38] OF WORD you can't use a variable to reach your table yourtable[1,1]
But with ARRAY [1..6] OF ARRAY[1..38] OF WORD you can easly use a boucle FOR to search what you want in your table yourtable[1][1] OR yourtable[iIndex1][iIndex2]
Thanks for your comment @ludecus, in any case, I'm very familiar with pointers and use them extensively in my daily basis, but it's not the solution I'm after now.
Thanks again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all,
I am working on a program in which I have declared one two dimensional array like this:
This array holds 38 words of raw data for 6 machine parts.
I need to pass the second dimension array to a function:
But, when I try to call the function like this:
myDataReceiverFunction(arrRawData[1]);
The compiler alerts me that: Cannot convert type 'WORD' to type 'ARRAY[1..38]OF WORD'.
I can use pointers, but, is there any easier syntax that would allow me to do this?
Thank you in advance!
Related
Talk.ru: 1
Answering myself just in case other people gets stuck here:
I should have declared the array like this:
Then my syntax does not make the compiler to go nuts.
So it is solved.
An explaination what is happening:
When you declare the array it is basically a custom variable type and the input to the function needs to match exactly that even though the second dimension would look the same as a one dimensional array uncompiled.
What's actually the difference between ARRAY [1..6,1..38] OF WORD, and ARRAY [1..6] OF ARRAY[1..38] OF WORD? It seems to me that they're the same thing. In either case arrRawData[1] should be an ARRAY [1..38] OF WORD. Other programming languages treat arrays in this way, is this just one of those Codesys quirks?
Hi,
Not sure but :
If you use ARRAY [1..6,1..38] OF WORD you can't use a variable to reach your table yourtable[1,1]
But with ARRAY [1..6] OF ARRAY[1..38] OF WORD you can easly use a boucle FOR to search what you want in your table yourtable[1][1] OR yourtable[iIndex1][iIndex2]
Related
Talk.ru: 1
Maybe I misunderstand what you're saying, but I regularly index 2 dimensional arrays with variables, for example:
@tvm it seems that you can't pass myArray[3] (from your example code) into a function that expects to get an array of 10 INTs.
Not a big deal, but seems strange.
Related
Talk.ru: 3
While you need to work with array, there are two options:
Declare a dynamic array size as input of the function (maybe it could require a FB instead)
During the compile the size of the dynamic array will be scaled.
Or you could use a pointer
Within the function or FB the pointer should be handled.
At least both ways are more generic, if the array size has been changed.
Thanks for your comment @ludecus, in any case, I'm very familiar with pointers and use them extensively in my daily basis, but it's not the solution I'm after now.
Thanks again.