<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to How to create an array dynamically</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f11f17e8b7/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f11f17e8b7/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f11f17e8b7/</id><updated>2020-02-27T20:33:45.411000Z</updated><subtitle>Recent posts to How to create an array dynamically</subtitle><entry><title>How to create an array dynamically</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f11f17e8b7/?limit=25#1591" rel="alternate"/><published>2020-02-27T20:33:45.411000Z</published><updated>2020-02-27T20:33:45.411000Z</updated><author><name>spfeif</name><uri>https://forge.codesys.com/u/spfeif/</uri></author><id>https://forge.codesys.com564952b30927e32cf1e3c499231bda0215fade0b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Robkristiaan is correct but if you are trying to change an upper bound "globally" like inside functions you build in a library ect... You can use a global constant like:&lt;/p&gt;
&lt;p&gt;VAR_GLOBAL CONSTANT&lt;/p&gt;
&lt;p&gt;MAX_ALARM_INDEX   :INT    := 24;  &lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;then you can change it in one place in the global variables and use it like:&lt;/p&gt;
&lt;p&gt;MyArray :ARRAY&lt;span&gt;[0..MAX_ALARM_INDEX]&lt;/span&gt; OF INT; &lt;/p&gt;
&lt;p&gt;Make sure you select (Check box) in the PROJECT-OPTIONS-BUILD menu "Replace Constants" other wise you will get a compile error. &lt;/p&gt;
&lt;p&gt;This is the closest to getting a dynamic array allocation by replacing with a constant.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to create an array dynamically</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f11f17e8b7/?limit=25#e532" rel="alternate"/><published>2020-02-27T20:33:41.447000Z</published><updated>2020-02-27T20:33:41.447000Z</updated><author><name>robkristiaan</name><uri>https://forge.codesys.com/u/robkristiaan/</uri></author><id>https://forge.codesys.com4945e5dff4831bf9f6a21c297e3892610396498c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;It is not possible to create a dynamic array,&lt;/p&gt;
&lt;p&gt;CoDeSys allocates the memory at build time not at runtime.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to create an array dynamically</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f11f17e8b7/?limit=25#8bd8" rel="alternate"/><published>2020-02-27T20:33:40.047000Z</published><updated>2020-02-27T20:33:40.047000Z</updated><author><name>erminio79</name><uri>https://forge.codesys.com/u/erminio79/</uri></author><id>https://forge.codesys.comc90e586995fd81f35e187732f49dc83431bd22f8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello everybody,&lt;/p&gt;
&lt;p&gt;it's possible to create an array dynamically?&lt;/p&gt;
&lt;p&gt;I need to create something like this:&lt;/p&gt;
&lt;p&gt;FUNCTION_BLOCK example&lt;/p&gt;
&lt;p&gt;VAR_INPUT&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;_UpperBound&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;VAR_OUTPUT&lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;VAR&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;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;UpperBound&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;/pre&gt;&lt;/div&gt;


&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;UpperBound :=_UpperBound;&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;PROGRAM MAIN&lt;/p&gt;
&lt;p&gt;VAR&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;     &lt;span class="nt"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

     &lt;span class="nt"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;example&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;x := 3;&lt;/p&gt;
&lt;p&gt;ex(_UpperBound := x);&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Does someone can help me ? &lt;/p&gt;
&lt;p&gt;Thanks for you help by advance.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>