<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Return Array Upper Bound</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/cbed940380/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/cbed940380/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/cbed940380/</id><updated>2020-02-27T21:36:37.080000Z</updated><subtitle>Recent posts to Return Array Upper Bound</subtitle><entry><title>Return Array Upper Bound</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/cbed940380/?limit=25#14c6" rel="alternate"/><published>2020-02-27T21:36:37.080000Z</published><updated>2020-02-27T21:36:37.080000Z</updated><author><name>Ralph Holz</name><uri>https://forge.codesys.com/u/ralph-holz/</uri></author><id>https://forge.codesys.come6795ceaa5f561e44a50a4512e9cf333d207b459</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ups sorry, thats exacly what i meant! &lt;/p&gt;
&lt;p&gt;Yes you can use constants in declaration to define the array bounds.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&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;0&lt;/span&gt;..&lt;span class="nv"&gt;UpperBound&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;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt; &lt;span class="nv"&gt;CONSTANT&lt;/span&gt;
&lt;span class="nv"&gt;UpperBound&lt;/span&gt;: &lt;span class="nv"&gt;INT&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&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;for&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;UpperBound&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="nv"&gt;something&lt;/span&gt;
&lt;span class="nv"&gt;end_for&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Ralph&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Return Array Upper Bound</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/cbed940380/?limit=25#7722" rel="alternate"/><published>2020-02-27T21:36:35.393000Z</published><updated>2020-02-27T21:36:35.393000Z</updated><author><name>spfeif</name><uri>https://forge.codesys.com/u/spfeif/</uri></author><id>https://forge.codesys.comf1d5a17f8b6e8588d18fffc7bf4d3593adff2ed2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;That is how I solved it as well. My situation was I have about 10- 15 small functions that compared and retrieved information out of an array of structures. In the event that I need to shrink or expand the size I didn't want to change 10-15 functions. So I just used a global array index as you noted and all is good. &lt;/p&gt;
&lt;p&gt;Although I will try it can you use a constant to declare an array size?&lt;/p&gt;
&lt;p&gt;In other words&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;Var&lt;/span&gt; &lt;span class="n"&gt;constant&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;ARRAY_INDEX&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;8&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&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;MyArray&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="n"&gt;ARARY_INDEX&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;/div&gt;</summary></entry><entry><title>Return Array Upper Bound</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/cbed940380/?limit=25#448b" rel="alternate"/><published>2020-02-27T21:36:33.836000Z</published><updated>2020-02-27T21:36:33.836000Z</updated><author><name>Ralph Holz</name><uri>https://forge.codesys.com/u/ralph-holz/</uri></author><id>https://forge.codesys.com8e67cfbaf2a87a1476b49aaad2dec76ddaa33233</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Steve,&lt;/p&gt;
&lt;p&gt;No there is no way to do that. &lt;/p&gt;
&lt;p&gt;I always use constants to declare arrays and by doing that i get the bounds of the array.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&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;0&lt;/span&gt;..&lt;span class="mi"&gt;8&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;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt; &lt;span class="nv"&gt;CONSTANT&lt;/span&gt;
&lt;span class="nv"&gt;UpperBound&lt;/span&gt;: &lt;span class="nv"&gt;INT&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&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;for&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;UpperBound&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="nv"&gt;something&lt;/span&gt;
&lt;span class="nv"&gt;end_for&lt;/span&gt; 
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;regards &lt;/p&gt;
&lt;p&gt;Ralph&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Return Array Upper Bound</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/cbed940380/?limit=25#7a8f" rel="alternate"/><published>2020-02-27T21:36:29.720000Z</published><updated>2020-02-27T21:36:29.720000Z</updated><author><name>spfeif</name><uri>https://forge.codesys.com/u/spfeif/</uri></author><id>https://forge.codesys.com81acb386f6af70f0eb01fa35f4f547c91c44132a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I thought I have done this in the past but can't find the code. Is there a function to return the upper bound to an array dynamically? For instance&lt;/p&gt;
&lt;p&gt;MyArray :Array&lt;span&gt;[0..8]&lt;/span&gt; of int;&lt;/p&gt;
&lt;p&gt;for i := 0 to MAX(MyArray) do&lt;/p&gt;
&lt;p&gt;something&lt;/p&gt;
&lt;p&gt;end_for&lt;/p&gt;
&lt;p&gt;As long as it returns either the number of elements or the Max index.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>