<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Array declaration with FB_Init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/1d102b5984/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/1d102b5984/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/1d102b5984/</id><updated>2020-08-21T13:59:05.756000Z</updated><subtitle>Recent posts to Array declaration with FB_Init</subtitle><entry><title>Array declaration with FB_Init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/1d102b5984/?limit=25#c279" rel="alternate"/><published>2020-08-21T13:59:05.756000Z</published><updated>2020-08-21T13:59:05.756000Z</updated><author><name>aikapan</name><uri>https://forge.codesys.com/u/aikapan/</uri></author><id>https://forge.codesys.com6fbf21b0f97801887f50ad3aaadf8d075f45e83d</id><summary type="html">&lt;div class="markdown_content"&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;2&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;MyObject&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;**[&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;];&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;get rid of this! Do it like the following:&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;2&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;MyObject&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;];&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then intellisense works at least at the first line though&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Array declaration with FB_Init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/1d102b5984/?limit=25#800b" rel="alternate"/><published>2020-02-27T13:56:28.073000Z</published><updated>2020-02-27T13:56:28.073000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.coma23d0d3c752bda07c456c57441405c06910815e2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;I have found adding VAR_INPUTS to Fb_init() to be a little troubling - intellisense doesn't show the VAR_INPUTS, so there are no hints to the user.  Also, an unfriendly error "No matching FB_init method found for instantiation...".  So, I normally just create my own "init" method that I call during first boot and initialize necessary items.  A bit of a workaround, but also very clear what is happening to other programmers:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="nv"&gt;MyObject&lt;/span&gt;
&lt;span class="nv"&gt;METHOD&lt;/span&gt; &lt;span class="nv"&gt;MyInit&lt;/span&gt;
&lt;span class="nv"&gt;VAR_INPUT&lt;/span&gt;
   &lt;span class="nv"&gt;ID&lt;/span&gt;: &lt;span class="nv"&gt;UINT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
...
&lt;span class="nv"&gt;END_METHOD&lt;/span&gt;
&lt;span class="nv"&gt;PROGRAM&lt;/span&gt; &lt;span class="nv"&gt;PLC_PRG&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt;
   &lt;span class="nv"&gt;MyArray&lt;/span&gt;: &lt;span class="nv"&gt;ARRAY&lt;/span&gt;[&lt;span class="mi"&gt;1&lt;/span&gt;..&lt;span class="mi"&gt;2&lt;/span&gt;] &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;MyObject&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;FirstBoot&lt;/span&gt;: &lt;span class="nv"&gt;BOOL&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;FirstBoot&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="nv"&gt;MyArray&lt;/span&gt;[&lt;span class="mi"&gt;1&lt;/span&gt;].&lt;span class="nv"&gt;MyInit&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ID&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;MyArray&lt;/span&gt;[&lt;span class="mi"&gt;2&lt;/span&gt;].&lt;span class="nv"&gt;MyInit&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ID&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   ...
   &lt;span class="nv"&gt;FirstBoot&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;FALSE&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
...
&lt;span class="nv"&gt;END_PROGRAM&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Array declaration with FB_Init</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/1d102b5984/?limit=25#9531" rel="alternate"/><published>2020-02-27T13:56:27.820000Z</published><updated>2020-02-27T13:56:27.820000Z</updated><author><name>DavidWSteadman</name><uri>https://forge.codesys.com/u/davidwsteadman/</uri></author><id>https://forge.codesys.comb85efada365a7c2c49ba3e735e86b4fc10a9b817</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I created an empty function block called MyObject, then declared an array of instances of the function block, as such:&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;2&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;MyObject&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So far, so good.  Now I add an FB_Init method to MyObject:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;METHOD&lt;/span&gt; &lt;span class="nv"&gt;FB_Init&lt;/span&gt; : &lt;span class="nv"&gt;Bool&lt;/span&gt;
&lt;span class="nv"&gt;VAR_INPUT&lt;/span&gt;
  &lt;span class="nv"&gt;bInitRetains&lt;/span&gt; : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;; // if TRUE, the retain variables are initialized (warm start / cold start)&lt;/span&gt;
  &lt;span class="nv"&gt;bInCopyCode&lt;/span&gt; : &lt;span class="nv"&gt;BOOL&lt;/span&gt;&lt;span class="c1"&gt;;  // if TRUE, the instance afterwards gets moved into the copy code (online change)&lt;/span&gt;
  &lt;span class="nv"&gt;ID&lt;/span&gt; : &lt;span class="nv"&gt;UINT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The question is, how do I now declare an array of MyObject?  My original declaration doesn't work any more because the objects can't be created without the 'ID' parameter.  But I can't figure out any way to pass it in.  I was hoping something along the lines of this would work:&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;2&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;MyObject&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;];&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;but that doesn't compile.&lt;/p&gt;
&lt;p&gt;Any suggestions on how to do this?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>