<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Array &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Wed, 23 Oct 2024 21:05:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Pair vs. Arrays and Dictionaries: Choosing the Right Tool For The Job</title>
		<link>https://blog.xojo.com/2024/10/24/pair-vs-arrays-and-dictionaries-choosing-the-right-tool-for-the-job/</link>
		
		<dc:creator><![CDATA[Gabriel Ludosanu]]></dc:creator>
		<pubDate>Thu, 24 Oct 2024 15:45:00 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Coding Best Practices]]></category>
		<category><![CDATA[Data Management]]></category>
		<category><![CDATA[Development Tips]]></category>
		<category><![CDATA[Dictionaries]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[Pair]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=13922</guid>

					<description><![CDATA[As developers, we are continuously seeking more refined and effective methods of data management for our apps. Although Arrays and Dictionaries receive the most attention,&#8230;]]></description>
										<content:encoded><![CDATA[
<p>As developers, we are continuously seeking more refined and effective methods of data management for our apps. Although <code>Arrays</code> and <code>Dictionaries</code> receive the most attention, there is another class, <code>Pair</code>, that is underutilized yet has great potential in certain contexts.</p>



<p>This article will cover the <code>Pair </code>class, highlight its strengths, compare it with <code>Arrays</code> and <code>Dictionaries</code>, and assist you in identifying the most suitable tool for your needs.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="what-is-the-pair-class">What is the Pair Class?</h2>



<p>In Xojo, the <code>Pair</code> class is a basic structure that stores two associated values: <code>Left </code>and <code>Right</code>. These properties can be of any data type, allowing you to pair together any two pieces of data.</p>



<pre class="wp-block-code"><code>Var myPair As New Pair("Pie", 15)
// or
Var myPair As Pair = "Pie" : 15</code></pre>



<p>In the example above, <code>myPair.Left</code> is <code>"Pie"</code> (a <code>String</code>), and <code>myPair.Right</code> is <code>15</code> (an <code>Integer</code>). The <code>Pair</code> class is especially handy when you need to associate two pieces of data without the overhead of creating a dedicated class or structure.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="scenarios-where-pair-excels">Advantages of Using the Pair Class</h2>



<p></p>



<h3 class="wp-block-heading" id="1-returning-multiple-values-from-a-method">1. Returning Multiple Values from a Method</h3>



<p>Sometimes, you need a method to return more than one value. While you could use <code>ByRef</code> parameters or create a custom class, using a <code>Pair</code> provides a quick and clean solution.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>Public Function GetMinMax(values() As Integer) As Pair
  Var minValue As Integer = values(0)
  Var maxValue As Integer = values(0)
  
  For Each value As Integer In values
    If value &lt; minValue Then minValue = value
    If value &gt; maxValue Then maxValue = value
  Next
  
  Return New Pair(minValue, maxValue)
End Function

// Usage
Var numbers() As Integer = Array(5, 2, 8, 3, 9)
Var result As Pair = GetMinMax(numbers)
MessageBox("Min: " + result.Left.StringValue + ", Max: " + result.Right.StringValue)
</code></pre>



<h3 class="wp-block-heading" id="2-associating-related-data-temporarily">2. Associating Related Data Temporarily</h3>



<p>When processing data, you might need to temporarily associate two values without persisting them or creating a complex data structure.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>Var people() As Pair
people.Append(New Pair("Alice", 30))
people.Append(New Pair("Bob", 25))
people.Append(New Pair("Charlie", 35))

For Each person As Pair In people
  MessageBox(person.Left.StringValue + " is " + person.Right.IntegerValue.ToString + " years old.")
Next
</code></pre>



<h3 class="wp-block-heading" id="3-key-value-pair-entries">3. Representation of Key-Value Pairs</h3>



<p>While Dictionaries are designed for key-value storage, sometimes you might need to represent key-value pairs explicitly, such as when iterating over a Dictionary&#8217;s entries.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>Var dict As New Dictionary
dict.Value("Red") = "#FF0000"
dict.Value("Green") = "#00FF00"
dict.Value("Blue") = "#0000FF"

For Each key As Variant In dict.Keys
  Var entry As New Pair(key, dict.Value(key))
  MessageBox(entry.Left.StringValue + " color code is " + entry.Right.StringValue)
Next
</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="pair-vs-arrays-vs-dictionaries">Comparison: Pair vs. Arrays vs. Dictionaries</h2>



<p>Understanding when to use the <code>Pair</code> class over <code>Arrays</code> or <code>Dictionaries</code> is crucial for writing efficient code.</p>



<h3 class="wp-block-heading" id="pair">Pair</h3>



<ul class="wp-block-list">
<li><strong>Structure:</strong> Holds exactly two related values (<code>Left</code> and <code>Right</code>).</li>



<li><strong>Type Safety:</strong> Both <code>Left</code> and <code>Right</code> can be any data type.</li>



<li><strong>Usage:</strong> Ideal for associating two pieces of data temporarily or for methods that need to return two values.</li>



<li><strong>Performance:</strong> Lightweight and minimal overhead.</li>
</ul>



<h3 class="wp-block-heading" id="arrays">Arrays</h3>



<ul class="wp-block-list">
<li><strong>Structure:</strong> Ordered collection of elements, accessible by index.</li>



<li><strong>Type Safety:</strong> Elements are of the same data type (unless you use <code>Variant</code> arrays).</li>



<li><strong>Usage:</strong> Best when dealing with lists of items where order matters.</li>



<li><strong>Performance:</strong> Efficient for iterating over large collections.</li>
</ul>



<h3 class="wp-block-heading" id="dictionaries">Dictionaries</h3>



<ul class="wp-block-list">
<li><strong>Structure:</strong> Collection of key-value pairs, with unique keys.</li>



<li><strong>Type Safety:</strong> Keys are typically <code>String</code> or <code>Integer</code>, values can be any data type.</li>



<li><strong>Usage:</strong> When you need fast lookup of values by keys.</li>



<li><strong>Performance:</strong> Optimized for key-based access; overhead of hash table management.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="when-to-choose-pair-over-arrays-or-dictionaries">Considerations for Using Pair Instead of Arrays or Dictionaries</h2>



<ul class="wp-block-list">
<li><strong>Simplicity:</strong> When you need to associate two items without creating a complex structure.</li>



<li><strong>Temporary Associations:</strong> For short-lived pairings within methods or loops.</li>



<li><strong>Returning Multiple Values:</strong> When methods need to return two related results.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="best-practices-with-pair">Best Practices with Pair</h2>



<ul class="wp-block-list">
<li><strong>Immutable Data:</strong> Since <code>Pair</code> is a class, be cautious when modifying <code>Left</code> or <code>Right</code> properties, especially if the <code>Pair</code> is shared among different parts of your code.</li>



<li><strong>Descriptive Code:</strong> Use comments or naming conventions to clarify what <code>Left</code> and <code>Right</code> represent, as they do not provide semantic meaning on their own.</li>
</ul>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code>// Pair: Left = Product Name, Right = Price
Var productPair As New Pair("Laptop", 999.99)</code></pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="limitations-of-pair">Drawbacks and Constraints of the Pair Class</h2>



<ul class="wp-block-list">
<li><strong>Lack of Clarity:</strong> Unlike custom classes or structures, <code>Pair</code> does not convey the meaning of its contents through property names.</li>



<li><strong>Fixed Size:</strong> Limited to exactly two items; for more complex data, consider using a class or structure.</li>



<li><strong>Reference Type:</strong> Being a class, <code>Pair</code> is a reference type, which can have implications for memory management and threading.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>



<p>The <code>Pair</code> class is a handy tool that can simplify your code when you need to associate two related values. While it doesn&#8217;t replace <code>Arrays</code> or <code>Dictionaries</code>, the <code>Pair</code> class is valuable in particular situations that prioritize simplicity and efficiency.</p>



<p><strong>Resources</strong>:</p>



<ul class="wp-block-list">
<li>Learn more about <a href="https://documentation.xojo.com/api/language/pair.html" data-type="link" data-id="https://documentation.xojo.com/api/language/pair.html" target="_blank" rel="noreferrer noopener">Pair</a></li>



<li>Learn more about <a href="https://documentation.xojo.com/api/language/arrays.html" data-type="link" data-id="https://documentation.xojo.com/api/language/arrays.html">Arrays</a></li>



<li>Learn more about <a href="https://documentation.xojo.com/api/language/dictionary.html" data-type="link" data-id="https://documentation.xojo.com/api/language/dictionary.html">Dictionary</a></li>
</ul>



<p><em>Gabriel is a digital marketing enthusiast who loves coding with Xojo to create cool software tools for any platform. He is always eager to learn and share new ideas!</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Working with Arrays: Assignment vs Copy</title>
		<link>https://blog.xojo.com/2019/09/18/working-with-arrays-assignment-vs-copy/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Wed, 18 Sep 2019 10:00:47 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Array]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6037</guid>

					<description><![CDATA[If you&#8217;re starting to program with Xojo, then you&#8217;ll probably soon find yourself in a situation where you need to use one of the Container&#8230;]]></description>
										<content:encoded><![CDATA[<p>If you&#8217;re starting to program with Xojo, then you&#8217;ll probably soon find yourself in a situation where you need to use one of the Container types: Array. In this case, it&#8217;s also probable that you might be confused at first as to why you don&#8217;t get what you expected when assigning the contents of a source Array to a target Array via the assignment operator (&#8220;=&#8221;).<span id="more-6037"></span></p>
<p>After all, when using the following snippet of code we could (wrongly) expect that the contents stored in the <code>ATarget</code> Array would be the same that the ones stored in the <code>ASource</code> Array. Of course, and at a first glance, this is the case. Try to write the following fragment in the Opening Event of a new Xojo Project or Method created by yourself (don&#8217;t forget to call such method, if you decide to follow that path):</p>
<pre>Var ASource() As Integer = Array(1,2,3,4,5,6,7,8)
Var ATarget() As Integer
ATarget = ASource</pre>
<p>If you set a breakpoint in the last line of code and execute your test app, then you&#8217;ll see that, as exepected, the contents of the <code>ATarget()</code> Array are the same that the ones stored by the <code>ASource()</code> Array. (Navigate through the Debugger Inspector Panel to inspect these variables)</p>
<p>However, what happens if we add the following line of code at the end of our fragment of code?:</p>
<pre>ASource.ResizeTo(-1)</pre>
<p>In this case we will be redimensioning the storage capacity of our <code>ASource()</code> Array with a total of 0 items. That is, in practice we will be <em>emptying</em> the Array.</p>
<p>As result of this operation you could expect that, while the contents of the <code>ASource()</code> variable are emptied, your <code>ATarget()</code> Array will continue storing their items. </p>
<p>The truth is that it doesn&#8217;t.</p>
<h2>This is how Array Assignment Works</h2>
<p>When we use the assignement operator (=) to set the values (items) of an Array to another one, what in fact happens behind the scenes is that the target Array will store only a reference to the source Array (the right-side value of the assignement operator), and not a copy of the values/objects stored.</p>
<p>Thus, and because they are references, all the operations we do on the source Array will be reflected in the target Array.</p>
<p>If you want to see that for yourself, try to delete the previous breakpoint and put a new one in the last line of code added.</p>
<p>When you run the now modified code, using the IDE Debugger feature to run the line of code where the Debugger has stopped, you&#8217;ll see how both Array variables (<code>ASource</code> and <code>ATarget</code>) reveal that their dimensions are -1. That is: when you <em>clean</em> the source Array using the <code>ResizeTo</code> method that change is also reflected in the target Array.</p>
<p>Why does this happens?</p>
<h2>Better Understanding: Reference vs Copy</h2>
<p>All the apps you execute in your computer or any other device are stored in memory, both the code to be executed and the Objects created and used during all the application lifetime.</p>
<p>For example, when we declare a variable in our example code (in this case an Array of Integer type), we can think about that variable as a mere label pointing to the starting cell of memory where will be stored the values later. We could visually represent that as this:</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-6038 size-large" src="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM-1024x94.png" alt="" width="1024" height="94" srcset="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM-1024x94.png 1024w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM-300x27.png 300w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM-768x70.png 768w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM.png 1431w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>So, this could be the visual representation of the memory when we add new items on the Array, although the real Xojo implementation of the stored values for an Array can differ from this. It doesn&#8217;t needs to be a contiguous region of memory or even the same structure to represent an Array in memory:</p>
<p><img decoding="async" class="wp-image-6039 size-large alignright" src="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion-1024x94.png" alt="" width="1024" height="94" srcset="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion-1024x94.png 1024w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion-300x27.png 300w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion-768x70.png 768w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion.png 1431w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>However, when we use the assignment operator (&#8220;=&#8221;) to set the contents of our <code>ASource()</code> Array to the <code>ATarget</code> Array what happens is that the value set for the <code>ATarget()</code> variable is the same memory position used by the <code>ASource()</code> variable; so all the operations made on the <code>ASource()</code> object (memory region) will be also reflected on <code>ATarget()</code>:</p>
<p><img decoding="async" class="wp-image-6040 size-large alignright" src="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion_referencia-1024x197.png" alt="" width="1024" height="197" srcset="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion_referencia-1024x197.png 1024w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion_referencia-300x58.png 300w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion_referencia-768x148.png 768w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Asignacion_referencia.png 1431w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>Conversely, when we iterate the items stored in the <code>ASource()</code> Array and use the <code>Add</code> method on the <code>ATarget()</code> Array, what happens is that the target Array will get and use its own memory region to store its own <b>copy</b> of the added values and, thus, is independent of the memory region used by the source Array.</p>
<p>This way, all the opeations made on the items pointed by the source Array will not be reflected on the target Array:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-6041 size-large" src="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Copia-1024x197.png" alt="" width="1024" height="197" srcset="https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Copia-1024x197.png 1024w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Copia-300x58.png 300w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Copia-768x148.png 768w, https://blog.xojo.com/wp-content/uploads/2019/09/Var_a_RAM_Copia.png 1431w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>
<h2> </h2>
<h2>Copying Array Items</h2>
<p>So, if what we really want to do is have our target Array stores its own copies of a source Array items, then we need to change from a simple assignment to an iteration and addition of the iterated values.</p>
<p>For that we need to use the <code>Add</code> Method on the target Array; while to access every item stored in the source Array we need to employ its index position in the Array (for example, <code>ASource(0)</code> will get the first item stored in the Array, while <code>ASource.LastIndex</code> will gives us the index position of the last added value).</p>
<p>Replace the previous code example with this one:</p>
<pre>Var ASource() As Integer = Array(1,2,3,4,5,6,7,8)<br />Var ATarget() As Integer 
Var Max As Integer = ASource.LastIndex
For n As Integer = 0 to Max
 ATarget().Add ASource(n)
Next
ASource.ResizeTo(-1)</pre>
<p>Now, if you set the a Debugger breakpoint in the last line of code and execute the application, then you&#8217;ll see, after executing the last line of code, our <code>ATarget()</code> Array will keep its own set of values, even after redimensioning the <code>ASource()</code> Array with the equivalent to &#8220;reserve storage for no items&#8221;, thus cleaning the region of memory used by such variable.</p>
<p>You can see all this in action in the following video (in Spanish):</p>
<p><iframe loading="lazy" title="Uso de Array (I)" width="500" height="281" src="https://www.youtube.com/embed/VBfkjiIrNtE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>


<p><em>Javier Rodri­guez has been&nbsp;the Xojo Spanish&nbsp;Evangelist since 2008, he’s also a Developer, Consultant and Trainer who&nbsp;has be using&nbsp;Xojo since 1998. He manages&nbsp;<a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers, GuancheID, AXImageCanvas, Markdown Parser for Xojo, HTMLColorizer for Xojo and the Snippery app, among others.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Case-Sensitive Array Sorting</title>
		<link>https://blog.xojo.com/2019/09/11/case-sensitive-array-sorting/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 11 Sep 2019 10:00:00 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6031</guid>

					<description><![CDATA[A customer on the forum was asking for a way to do case-sensitive array sorting. The built-in array Sort command uses case-insensitive sorting and they&#8230;]]></description>
										<content:encoded><![CDATA[
<p>A <a href="https://forum.xojo.com/55837-does-anyone-know-of-a-case-sensitive-sort-function">customer on the forum</a> was asking for a way to do case-sensitive array sorting. The built-in array <a href="https://documentation.xojo.com/api/language/sort.html">Sort command</a> uses case-insensitive sorting and they wanted an alternative.</p>



<p>It turns out it is super-easy to use the <a href="https://documentation.xojo.com/api/language/sort.html">Sort(Delegate) method</a> to create your own sorting method and then pass it to the call to sort.</p>



<span id="more-6031"></span>



<p>The sorting method would use StrComp to get a case-sensitive sort and could look like this:</p>



<pre class="wp-block-preformatted">Public Function CaseSensitiveSort(value1 As String, value2 As String) as Integer
   Return StrComp(value1, value2, Realbasic.StrCompCaseSensitive)
End Function</pre>



<p>And then you can call it like this:</p>



<pre class="wp-block-preformatted">Dim s() As String = Array("alpha", "Test", "Beta", "candy")
s.Sort(AddressOf CaseSensitiveSort)</pre>



<p>To get this sorted result:</p>



<ul class="wp-block-list"><li>Beta</li><li>Test</li><li>alpha</li><li>candy</li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>#JustCode Challenge Week 4 &#8211; Mini Golf ScoreKeeper</title>
		<link>https://blog.xojo.com/2018/07/13/justcode-challenge-week-4-mini-golf-scorekeeper/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Fri, 13 Jul 2018 08:05:11 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[#JustCode]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=4387</guid>

					<description><![CDATA[Sometimes the idea for a great little app comes down to solving a silly little problem. Last month, the family went mini-golfing for my son&#8217;s&#8230;]]></description>
										<content:encoded><![CDATA[<p><span style="font-size: 16px;">Sometimes the idea for a great little app comes down to solving a silly little problem.</span></p>
<p>Last month, the family went mini-golfing for my son&#8217;s birthday. It was a lovely course called Pirate&#8217;s Cove Adventure Golf right next to the ocean. But they didn&#8217;t have scoring stands and we had to use a tiny pencil on a little cardboard scorecard to keep score. So this week&#8217;s app is a simple iOS app track of mini-golf scores!</p>
<p>The iOS app has two screens. The main screen has a giant Table that lists all the 18 holes. You tab on the detail button for a row (it&#8217;s the &#8220;I&#8221; icon) to go to the scoring screen.</p>
<p><span id="more-4387"></span></p>
<p>The scoring screen has places to enter scores for up to four players. It also keeps a running score total for each player.</p>
<p>The scores are stored in a two-dimensional array that is 4 x 18. Keep in mind that Xojo arrays are 0-based so this array is declared, as a property on the App object, with these dimensions: 3 x 17.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4541" src="https://blog.xojo.com/wp-content/uploads/2018/07/2018-07-10_16-08-27.png" alt="" width="392" height="770" /><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4542" src="https://blog.xojo.com/wp-content/uploads/2018/07/2018-07-10_16-08-27-1.png" alt="" width="392" height="770" /></p>
<p><a href="http://files.xojo.com/JustCode/MiniGolf.xojo_binary_project.zip">Download the Mini Golf project</a>.</p>
<p>This app is pretty simple, so here are some ideas for enhancements:</p>
<ul>
<li>Enter and display player names</li>
<li>Allow for more than 4 people on a team</li>
<li>Allow entry for &#8220;par&#8221; for each hole</li>
<li>Give each hole a name and save it separately so you can reload it should you go there to play often</li>
</ul>
<p>Download and check out earlier projects:</p>
<ul>
<li>Week 3: <a href="https://blog.xojo.com/2018/07/06/just-code-challenge-week3/">Dogs Up!</a></li>
<li>Week 2: <a href="https://blog.xojo.com/2018/06/29/just-code-challenge-week2/">Password Generator</a></li>
<li>Week 1: <a href="https://blog.xojo.com/2018/06/22/just-code-challenge-week1/">Color Picker</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
