<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/</id><updated>2022-05-10T16:08:24.147000Z</updated><subtitle>Recent posts to Pass the second array dimension into a function as a parameter</subtitle><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=25#ee8a" rel="alternate"/><published>2022-05-10T16:08:24.147000Z</published><updated>2022-05-10T16:08:24.147000Z</updated><author><name>joanm</name><uri>https://forge.codesys.com/u/joanm/</uri></author><id>https://forge.codesys.com881505d94587acf22643f1e8237895c52175adff</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for your comment &lt;a class="user-mention" href="/u/ludecus/"&gt;@ludecus&lt;/a&gt;, 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.&lt;/p&gt;
&lt;p&gt;Thanks again.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=50#b602" rel="alternate"/><published>2022-05-09T11:35:32.908000Z</published><updated>2022-05-09T11:35:32.908000Z</updated><author><name>ludecus</name><uri>https://forge.codesys.com/u/ludecus/</uri></author><id>https://forge.codesys.com4ac6557cadbc5d9deab3a34e47c01934092e7c7a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;While you need to work with array, there are two options:&lt;/p&gt;
&lt;p&gt;Declare a dynamic array size as input of the function (maybe it could require a FB instead)&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;VAR_IN_OUT&lt;/span&gt;
&lt;span class="err"&gt;    arrData : ARRY * OF WORD;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;During the compile the size of the dynamic array will be scaled.&lt;/p&gt;
&lt;p&gt;Or you could use a pointer&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt;    parrData : POINTER TO WORD;&lt;/span&gt;
&lt;span class="err"&gt;    nDataSize : UINT;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Within the function or FB the pointer should be handled.&lt;/p&gt;
&lt;p&gt;At least both ways are more generic, if the array size has been changed.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=25#630a" rel="alternate"/><published>2022-05-08T15:09:15.479000Z</published><updated>2022-05-08T15:09:15.479000Z</updated><author><name>joanm</name><uri>https://forge.codesys.com/u/joanm/</uri></author><id>https://forge.codesys.comb6bce27fada76e0448770f8244960606172f764e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;a class="user-mention" href="/u/tvm/"&gt;@tvm&lt;/a&gt; it seems that you can't pass myArray&lt;a class="alink" href="/forge/talk-ru/3/"&gt;[3]&lt;/a&gt; (from your example code) into a function that expects to get an array of 10 INTs.&lt;/p&gt;
&lt;p&gt;Not a big deal, but seems strange.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=50#f9d9/3e0d/e55c" rel="alternate"/><published>2022-05-05T13:59:29.917000Z</published><updated>2022-05-05T13:59:29.917000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com3f53dd2d56a7044a74502f8fe188abd9a42ab2ee</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Maybe I misunderstand what you're saying, but I regularly index 2 dimensional arrays with variables, for example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;myArray&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ARRAY&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;FOR&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;TO&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="n"&gt;DO&lt;/span&gt;
    &lt;span class="n"&gt;FOR&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;TO&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="n"&gt;DO&lt;/span&gt;
        &lt;span class="n"&gt;myArray&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;]:=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;END_FOR&lt;/span&gt;
&lt;span class="n"&gt;END_FOR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=25#f9d9/3e0d" rel="alternate"/><published>2022-05-05T13:51:30.498000Z</published><updated>2022-05-05T13:51:30.498000Z</updated><author><name>maretxa</name><uri>https://forge.codesys.com/u/maretxa/</uri></author><id>https://forge.codesys.com0f4613a9027d3ac711e72bd96df88dc03ccb13bd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Not sure but :&lt;br/&gt;
If you use ARRAY &lt;span&gt;[1..6,1..38]&lt;/span&gt; OF WORD you can't use a variable to reach your table yourtable&lt;span&gt;[1,1]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;But with ARRAY &lt;span&gt;[1..6]&lt;/span&gt; OF ARRAY&lt;span&gt;[1..38]&lt;/span&gt; OF WORD you can easly use a boucle FOR to search what you want in your table yourtable&lt;a class="alink" href="/forge/talk-ru/1/"&gt;[1]&lt;/a&gt;&lt;a class="alink" href="/forge/talk-ru/1/"&gt;[1]&lt;/a&gt; OR yourtable&lt;span&gt;[iIndex1]&lt;/span&gt;&lt;span&gt;[iIndex2]&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=50#f9d9" rel="alternate"/><published>2022-05-05T12:02:38.846000Z</published><updated>2022-05-05T12:02:38.846000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com3c54e27abe7a90694954ebd973eeea73792b9bb3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;What's actually the difference between ARRAY &lt;span&gt;[1..6,1..38]&lt;/span&gt; OF WORD, and ARRAY &lt;span&gt;[1..6]&lt;/span&gt; OF ARRAY&lt;span&gt;[1..38]&lt;/span&gt; OF WORD?  It seems to me that they're the same thing.  In either case arrRawData&lt;a class="alink" href="/forge/talk-ru/1/"&gt;[1]&lt;/a&gt; should be an ARRAY &lt;span&gt;[1..38]&lt;/span&gt; OF WORD.  Other programming languages treat arrays in this way, is this just one of those Codesys quirks?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=25#4773" rel="alternate"/><published>2022-05-05T07:59:30.279000Z</published><updated>2022-05-05T07:59:30.279000Z</updated><author><name>ojz0r</name><uri>https://forge.codesys.com/u/ojz0r/</uri></author><id>https://forge.codesys.com3e6c4b7505dcdcbbc89ccb8afe0f1d76277b985e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;An explaination what is happening:&lt;br/&gt;
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.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=25#ec8f" rel="alternate"/><published>2022-05-04T16:40:31.600000Z</published><updated>2022-05-04T16:40:31.600000Z</updated><author><name>joanm</name><uri>https://forge.codesys.com/u/joanm/</uri></author><id>https://forge.codesys.com6554307a7aa6a522141bb3594da42beb3c3d4103</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Answering myself just in case other people gets stuck here:&lt;/p&gt;
&lt;p&gt;I should have declared the array like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;arrRawData&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ARRAY&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;ARRAY&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;WORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then my syntax does not make the compiler to go nuts.&lt;/p&gt;
&lt;p&gt;So it is solved.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Pass the second array dimension into a function as a parameter</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/76face79ac/?limit=25#49c2" rel="alternate"/><published>2022-05-04T16:14:40.320000Z</published><updated>2022-05-04T16:14:40.320000Z</updated><author><name>joanm</name><uri>https://forge.codesys.com/u/joanm/</uri></author><id>https://forge.codesys.com43a83907739458ddd2c22d3edb4bb2a1580513b0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello all,&lt;/p&gt;
&lt;p&gt;I am working on a program in which I have declared one two dimensional array like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;arrRawData&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ARRAY&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;38&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;WORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This array holds 38 words of raw data for 6 machine parts.&lt;/p&gt;
&lt;p&gt;I need to pass the second dimension array to a function:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;FUNCTION myDataReceiverFunction : BOOL&lt;/span&gt;
&lt;span class="err"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt;  arrRawDataWords : ARRAY[1..38] OF WORD;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;span class="err"&gt;... &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But, when I try to call the function like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;myDataReceiverFunction(arrRawData[1]);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The compiler alerts me that: &lt;strong&gt;Cannot convert type 'WORD' to type 'ARRAY&lt;span&gt;&lt;span&gt;[1..38]&lt;/span&gt;&lt;/span&gt;OF WORD'&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I can use pointers, but, is there any easier syntax that would allow me to do this?&lt;/p&gt;
&lt;p&gt;Thank you in advance!&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>