<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Network Variable can't accept constants for array length??</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/</id><updated>2021-04-22T12:59:03.980000Z</updated><subtitle>Recent posts to Network Variable can't accept constants for array length??</subtitle><entry><title>Network Variable can't accept constants for array length??</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/?limit=25#e8d8" rel="alternate"/><published>2021-04-22T12:59:03.980000Z</published><updated>2021-04-22T12:59:03.980000Z</updated><author><name>bosulliv</name><uri>https://forge.codesys.com/u/bosulliv/</uri></author><id>https://forge.codesys.com4cfb73686d9a4e19dab9bc8d595fed73db078277</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;For anyone reading this later, it turns out that you CAN use constants, you just have to remove the auto-populated pragma &lt;em&gt;{attribute 'qualifiedonly'}&lt;/em&gt; and then only reference those constants using their un-qualified name.  Ex:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="cm"&gt;/*{attribute 'qualifiedonly'}*&lt;/span&gt;
&lt;span class="cm"&gt;VAR_GLOBAL CONSTANT&lt;/span&gt;
&lt;span class="cm"&gt;    test           :INT      := 3;&lt;/span&gt;
&lt;span class="cm"&gt;END_VAR&lt;/span&gt;
&lt;span class="cm"&gt;.&lt;/span&gt;
&lt;span class="cm"&gt;.&lt;/span&gt;
&lt;span class="cm"&gt;.&lt;/span&gt;
&lt;span class="cm"&gt;VAR_GLOBAL&lt;/span&gt;
&lt;span class="cm"&gt;    arr         : ARRAY[0..test] OF INT;   &lt;/span&gt;
&lt;span class="cm"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I can't imagine why the compiler can't recognize the variable as a constant if you use its fully qualified name (NVL_Constants.test vs test).  That really seems like a bug to me . . . and the requirement isn't documented in the Network Variable documentation.  Hopefully this can be corrected.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Network Variable can't accept constants for array length??</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/?limit=25#096b/a71c" rel="alternate"/><published>2021-04-20T12:37:33.663000Z</published><updated>2021-04-20T12:37:33.663000Z</updated><author><name>bosulliv</name><uri>https://forge.codesys.com/u/bosulliv/</uri></author><id>https://forge.codesys.com6114cd629456fe586d42a8632f99ce483c1f1f57</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I made the assumption that the documentation would not have a sentence that immediately contradicts the sentence that precedes it.  Maybe it meant that constant &lt;strong&gt;expressions&lt;/strong&gt; are not allowed but that constants are allowed?  The example you included shows an expression after all.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Network Variable can't accept constants for array length??</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/?limit=25#096b" rel="alternate"/><published>2021-04-20T06:50:42.242000Z</published><updated>2021-04-20T06:50:42.242000Z</updated><author><name>quirzo</name><uri>https://forge.codesys.com/u/quirzo/</uri></author><id>https://forge.codesys.comea1719c4d5cbb10e83882959373a197a88062f78</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;From the same page:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;Constant&lt;/span&gt; &lt;span class="nv"&gt;expressions&lt;/span&gt; &lt;span class="nv"&gt;are&lt;/span&gt; &lt;span class="nv"&gt;not&lt;/span&gt; &lt;span class="nv"&gt;permitted&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;this&lt;/span&gt; &lt;span class="nv"&gt;purpose&lt;/span&gt;.

&lt;span class="nv"&gt;Example&lt;/span&gt;: “&lt;span class="nv"&gt;arrVar&lt;/span&gt; : &lt;span class="nv"&gt;ARRAY&lt;/span&gt;[&lt;span class="mi"&gt;0&lt;/span&gt;..&lt;span class="nv"&gt;g_iArraySize&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;] &lt;span class="nv"&gt;OF&lt;/span&gt; &lt;span class="nv"&gt;INT&lt;/span&gt; &lt;span class="c1"&gt;;” is not transmitted, but “arrVar : ARRAY[0..10] OF INT ;” is transmitted.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So yes. Constants wont work.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Network Variable can't accept constants for array length??</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7e7140724c/?limit=25#d08a" rel="alternate"/><published>2021-04-19T15:27:21.090000Z</published><updated>2021-04-19T15:27:21.090000Z</updated><author><name>bosulliv</name><uri>https://forge.codesys.com/u/bosulliv/</uri></author><id>https://forge.codesys.comf303081234589c8fdd6fb6030c78442f0d89efcb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;In the &lt;a class="" href="https://help.codesys.com/api-content/2/codesys/3.5.13.0/en/_cds_f_networkvariables/#b52b48b2bfee395c0a8640e00293442-id-c7ef2a122c097414c0a8640e012d8eb8" rel="nofollow"&gt;documentation for network variables&lt;/a&gt; it states that arrays must &lt;strong&gt;"have limits defined with a literal or constant"&lt;/strong&gt;.  However any constant I have tried to use (defined with VAR_GLOBAL CONSTANT) throws the error:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;Network&lt;/span&gt; &lt;span class="n"&gt;Variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;GVL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;length&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;literal&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;constant&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I put together a simple test project to verify this.  Defining the following in a network variable is all it takes.  The constant can be defined in another global list or it can be defined right in the NVL, it will fail to compile:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;VAR_GLOBAL&lt;/span&gt; &lt;span class="n"&gt;CONSTANT&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt;           &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;INT&lt;/span&gt;      &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="n"&gt;VAR_GLOBAL&lt;/span&gt;
    &lt;span class="n"&gt;arr&lt;/span&gt;         &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;ARRAY&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="n"&gt;NVL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;OF&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Is the documentation wrong, and you can only use literals to define array length in Network Variables?  Or am I maybe misunderstanding what the the Network Variable needs to be properly defined?  Kind of at a brick wall here...&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>