<?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>Color &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/color/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 25 Mar 2025 15:57:00 +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>The MobileColorPicker Control Now Available for iOS Projects</title>
		<link>https://blog.xojo.com/2025/03/25/the-mobilecolorpicker-control-now-available-for-ios-projects/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 25 Mar 2025 15:34:19 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[2025r1]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=14550</guid>

					<description><![CDATA[Starting with Xojo 2025r1, you&#8217;ll find a new control in the iOS Library panel: MobileColorPicker. This control brings a native color-picking experience to your projects,&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Starting with Xojo 2025r1, you&#8217;ll find a new control in the iOS Library panel: MobileColorPicker. This control brings a native color-picking experience to your projects, allowing users to choose from a wide range of colors, save their favorites, or use a &#8216;<a href="https://en.wikipedia.org/wiki/Loupe">loupe</a>&#8216; to select a color directly from the screen.</p>



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



<p>Using the new control is similar to how you would use the same type of control in Desktop projects. For example, drag the control from the Library panel and drop it onto the Layout Editor of a Screen, where it will be added to the Tray area.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img fetchpriority="high" decoding="async" width="2500" height="1592" src="https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM.png" alt="" class="wp-image-14551" srcset="https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM.png 2500w, https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM-300x191.png 300w, https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM-1024x652.png 1024w, https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM-768x489.png 768w, https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM-1536x978.png 1536w, https://blog.xojo.com/wp-content/uploads/2025/02/Screenshot-2025-02-26-at-12.07.11 PM-2048x1304.png 2048w" sizes="(max-width: 2500px) 100vw, 2500px" /></figure>
</div>


<p>Next, you need to call the Show method on the MobileColorPicker instance to display it to the user, and implement the ColorSelected event handler to capture the selected color.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>Note:</strong> This control&#8217;s functionality is available only when the app is run on devices with iOS 14 or later (the minimum recommended version for iOS projects starting with Xojo 2025r1).</p>
</blockquote>



<h2 class="wp-block-heading">Modal vs Popover</h2>



<p>When calling the Show method without parameters on the MobileColorPicker instance, it will be displayed as a modal panel on both iPhone and iPad devices. If you provide the ParentControl parameter, the MobileColorPicker will be shown as a popover panel on iPad devices. However, on iPhone devices, it will still be displayed as a modal dialog, regardless of the ParentControl parameter.</p>



<figure class="wp-block-video"><video controls src="https://blog.xojo.com/wp-content/uploads/2025/02/Simulator-Screen-Recording-iPad-Air-5th-generation-2025-02-26-at-12.10.40.mp4"></video></figure>



<h2 class="wp-block-heading">In Summary</h2>



<p>The addition of the MobileColorPicker control in Xojo 2025r1 simplifies color selection in iOS apps, providing a native and intuitive experience for your users. This control makes it easier than ever to implement color pickers in your iOS projects. So, give it a try in your next app, and enhance the user experience!</p>



<p><em>Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón</em>, <em>Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at <a href="https://twitter.com/xojoes" target="_blank" rel="noreferrer noopener">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary" target="_blank" rel="noreferrer noopener">Xojo Forum</a>.</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>
					
		
		<enclosure url="https://blog.xojo.com/wp-content/uploads/2025/02/Simulator-Screen-Recording-iPad-Air-5th-generation-2025-02-26-at-12.10.40.mp4" length="321491" type="video/mp4" />

			</item>
		<item>
		<title>Tip: Setting the Background Color in WebDialogs</title>
		<link>https://blog.xojo.com/2021/06/08/tip-setting-the-background-color-in-webdialogs/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 08 Jun 2021 08:00:00 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[WebStyles]]></category>
		<category><![CDATA[Xojo API 2.0]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8606</guid>

					<description><![CDATA[I was recently asked how to set the background color in a WebDialog. There are a few approaches you can take to accomplish this. The simplest one is to add a rectangle as a layer of the WebDialog and set a color to it. In this tutorial you'll learn how to set the background cool by accessing the style property of the object in the DOM model and setting it there. ]]></description>
										<content:encoded><![CDATA[<p>I was recently asked how to set the background color in a <a href="https://documentation.xojo.com/api/user_interface/web/webdialog.html"><code>WebDialog</code></a>. There are a few approaches you can take to accomplish this. The simplest one is to add a rectangle as a layer of the <strong>WebDialog</strong> and set a color to it. In this tutorial you&#8217;ll learn how to set the background color by accessing the style property of the object in the <strong>DOM</strong> model and setting it there. <span id="more-8606"></span></p>
<p>First, add a new <code>Module</code> to a web project. For this tutorial we&#8217;ll name it <code>WebTools</code>. Next, add the following method to it with a <code>Global</code> scope:</p>
<ul>
<li><strong>Method Name:</strong> <code>ModalBackgroundColor</code></li>
<li><code></code><strong>Parameters:</strong> <code>Extends v As WebDialog, assigns c As String</code></li>
<li><code></code><strong>Scope:</strong> <code>Global</code></li>
</ul>
<p>And type the following snippet of code in the associated Code Editor:</p>
<pre>v.ExecuteJavascript("document.getElementById('" + v.ControlID + "_body').style.backgroundColor='"+c+"';")</pre>
<p>With that done, we only need to call it from the <code>Opening</code> Event Handler of a <code>WebDialog</code> instance to set the desired background color:</p>
<pre>Me.ModalBackgroundColor = "#f00" // Sets the background color to Red.</pre>
<p>This leads to some interesting side effects. For example, the header on the <a href="https://documentation.xojo.com/api/user_interface/web/weblistbox.html"><code>WebListbox</code></a> control and the loupe icon on the <a href="https://documentation.xojo.com/api/user_interface/web/websearchfield.html"><code>WebSearchField</code></a> are transparent. That means that they look good when the background color on the <code>WebDialog</code> is the default white color, but not so good when we set a different background color on the <code>WebDialog</code> instance.</p>
<p>Avoid this issue by accessing the <strong>Style</strong> property on the proper <code>div</code> class on these objects. The tricky part here is to access the instance number whose inner header class we need to change. For that, the approach taken here may be a bit of overkill, but it works.</p>
<p>Such an approach is based on subclassing those <code>WebControls</code> we need to reference. In this case we are going to create subclasses for the <code>WebListBox</code> and the <code>WebSearchField</code>.</p>
<p>Add a new class to the project and name it <code>MyWebListBox</code>, setting its <strong>Super</strong> to <code>WebListBox</code>. Next, add a new shared property with the following values:</p>
<ul>
<li><strong>Shared Property Name:</strong> <code>globalInstance</code></li>
<li><code></code><strong>Data Type:</strong> <code>Dictionary</code></li>
<li><code></code><strong>Scope:</strong> <code>Private</code></li>
</ul>
<p>And a second regular property with these values:</p>
<ul>
<li><strong>Property Name:</strong> <code>instanceNumber</code></li>
<li><code></code><strong>Data Type:</strong> <code>Integer</code></li>
<li><code></code><strong>Scope:</strong> <code>Public</code></li>
</ul>
<p>Next, add the <code>Constructor</code> method to the new class. The IDE will automatically include the code calling its <code>Super</code> class. Then, add a couple lines of code to set the <code>instanceNumber</code> property to the last index of the <code>globalInstance</code> shared property array. The final code for the method will look like this:</p>
<pre>Super.Constructor
If globalInstance = Nil Then globalInstance = New Dictionary
Var instances() As MyWebListBox
If Session &lt;&gt; Nil Then
  If globalInstance.HasKey(Session) Then
    instances = globalInstance.Value(Session)
  End If
  instances.add Me
  instanceNumber = instances.lastindex
  globalInstance.Value(Session) = instances
End If</pre>
<p>Add next the <code>Closed</code> Event handler to the subclass, typing the following snippet of code in the associated Code Editor:</p>
<pre>If Session &lt;&gt; Nil Then
  If globalInstance.HasKey(Session) Then
    Var instances() As MyWebListBox = globalInstance.Value(Session)
    instances.Remove(Me.instanceNumber)
    For n As Integer = Me.instanceNumber To instances.LastIndex
      instances(n).instanceNumber = instances(n).instanceNumber-1
    Next
    globalInstance.Value(Session) = instances
  End If
End If</pre>
<p>Because we are using the <code>Closed</code> event handler in the subclass, we need to add it again using the Event Definition option (keeping the same name, number of parameters and returned type). This way the instances based on this subclass will be able to add that event too.</p>
<p>Repeat the same steps to add a new <code>MyWebSearchField</code> class whose Super is set to <code>WebSearchField</code>.</p>
<p><img decoding="async" class="wp-image-8632 size-full aligncenter" src="https://blog.xojo.com/wp-content/uploads/2021/06/BacgroundWebClasses.png" alt="" width="290" height="422" srcset="https://blog.xojo.com/wp-content/uploads/2021/06/BacgroundWebClasses.png 290w, https://blog.xojo.com/wp-content/uploads/2021/06/BacgroundWebClasses-206x300.png 206w" sizes="(max-width: 290px) 100vw, 290px" /></p>
<p> </p>
<p>The code associated with the <code>Constructor</code> method for the <code>MyWebSearchField</code> is as follows:</p>
<pre>Super.Constructor
If globalInstance = Nil Then globalInstance = New Dictionary
If Session &lt;&gt; Nil Then
  Var instances() As MyWebSearchField
  If globalInstance.HasKey(Session) Then
    instances = globalInstance.Value(Session)
  End If
  instances.add Me
  instanceNumber = instances.lastindex  
  globalInstance.Value(Session) = instances
End If
</pre>
<p>And the code associated with the <code>Closed</code> Event Handler should be this one:</p>
<pre>If Session &lt;&gt; Nil Then
  If globalInstance.HasKey(Session) Then
    Var instances() As MyWebSearchField = globalInstance.Value(Session)
    instances.Remove(Me.instanceNumber)
    For n As Integer = Me.instanceNumber To instances.LastIndex
      instances(n).instanceNumber = instances(n).instanceNumber-1
    Next
    globalInstance.Value(Session) = instances
  End If
End If</pre>
<p>With both both classes created, add them to a WebDialog instance (the one we named <code>WebDialog1</code>). Then, include the following line of code in the <code>Shown</code> event handler for each of these instances:</p>
<p><img decoding="async" class="size-large wp-image-8608 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2021/06/SettingClasses-1024x495.png" alt="" width="1024" height="495" srcset="https://blog.xojo.com/wp-content/uploads/2021/06/SettingClasses-1024x495.png 1024w, https://blog.xojo.com/wp-content/uploads/2021/06/SettingClasses-300x145.png 300w, https://blog.xojo.com/wp-content/uploads/2021/06/SettingClasses-768x371.png 768w, https://blog.xojo.com/wp-content/uploads/2021/06/SettingClasses.png 1059w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>In the case of the <code>ListBox1</code> instance:</p>
<pre>Me.ExecuteJavascript("document.getElementsByClassName(""dataTables_scrollHeadInner"")["+me.instanceNumber.tostring+"].style.backgroundColor='#f00';") // This will set the listbox header background color to Red</pre>
<p>Of course, you can improve this by accepting a variable color reference string instead of using the constant red value here (&#8220;#f00&#8221;).</p>
<p>And for the <code>SearchField1</code> instance:</p>
<pre>Me.ExecuteJavascript("document.getElementsByClassName(""input-group-append"")["+me.instanceNumber.toString+"].style.backgroundColor='#fff';") // This will set the "loupe" icon background color to White</pre>
<p>Now, we need to make sure that both the <code>WebListbox</code> and the <code>WebSearchField</code> instances are reset when we are done, something we can do by calling their <code>Close</code> method from the <code>Dismissed</code> event handler added to the <code>WebDialog1</code> instance in the project:</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-8615 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2021/06/Dismissed.png" alt="" width="496" height="158" srcset="https://blog.xojo.com/wp-content/uploads/2021/06/Dismissed.png 496w, https://blog.xojo.com/wp-content/uploads/2021/06/Dismissed-300x96.png 300w" sizes="auto, (max-width: 496px) 100vw, 496px" /></p>
<p>Run the example project and you&#8217;ll see how the first ListBox instance (on the <code>WebPage1</code> page) keeps the header color as transparent (white, because the page background color is white), while the second one displayed by the WebDialog is set to red. Also, the SearchField control displays the loupe icon with a white background color.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-8609 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2021/06/WebDialogBGColor.png" alt="" width="934" height="473" srcset="https://blog.xojo.com/wp-content/uploads/2021/06/WebDialogBGColor.png 934w, https://blog.xojo.com/wp-content/uploads/2021/06/WebDialogBGColor-300x152.png 300w, https://blog.xojo.com/wp-content/uploads/2021/06/WebDialogBGColor-768x389.png 768w" sizes="auto, (max-width: 934px) 100vw, 934px" /></p>
<h2>Bonus Tip</h2>
<p>Once you know the mechanics of how to access the proper ID and set the background on the WebDialog, it is easy to set an image as the background instead of a color. For example, this line of code in the <code>Shown</code> event of the <code>WebDialog1</code> instance will load the Xojo logo as the background image:</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-8610 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2021/06/BackgroundImage.png" alt="" width="902" height="466" srcset="https://blog.xojo.com/wp-content/uploads/2021/06/BackgroundImage.png 902w, https://blog.xojo.com/wp-content/uploads/2021/06/BackgroundImage-300x155.png 300w, https://blog.xojo.com/wp-content/uploads/2021/06/BackgroundImage-768x397.png 768w" sizes="auto, (max-width: 902px) 100vw, 902px" /></p>
<pre>Me.ModalBackgroundImage = "https://www.xojo.com/assets/img/logo.png"</pre>
<p><code>ModalBackgroundImage</code> is another method added to the <code>WebTools</code> module using the following signature:</p>
<ul>
<li><strong>Method Name:</strong> <code>ModalBackgroundImage</code></li>
<li><code></code><strong>Parameters:</strong> <code>Extends v as WebDialog, Assigns url As String</code></li>
</ul>
<p>Add the following associated code:</p>
<pre>Var s As String = "document.getElementById('" + _
v.ControlID + "_body').style.backgroundImage=""url('"+url+"')"";"

v.ExecuteJavascript(s)</pre>
<p>Now that you have the basics down, you can go even further and set other background attributes such as not repeating the image, setting the image size and more.</p>


<p>Questions? Ask me on Twitter&nbsp;<a href="https://twitter.com/xojoes">@XojoES</a>&nbsp;or on the&nbsp;<a href="https://forum.xojo.com/u/javier_menendez/summary">Xojo Forum</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Setting Constants</title>
		<link>https://blog.xojo.com/2018/02/12/setting-constants/</link>
		
		<dc:creator><![CDATA[Norman Palardy]]></dc:creator>
		<pubDate>Mon, 12 Feb 2018 07:30:43 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[Constant]]></category>
		<category><![CDATA[RGBA]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=3869</guid>

					<description><![CDATA[A recent thread on the forums discussed why a particular bit of code would not compile he felt the error message seemed less than helpful: "CRghtColr As Color = Color.RGBA(000,061,255,208)". So, if you ever happen to see this, check to see that you are following the rules about what is allowed for the default value of a constant.]]></description>
										<content:encoded><![CDATA[<p>A <a href="https://forum.xojo.com/45837-bug-set-global-property-or-constant-to-rgba">recent thread</a> on the forums discussed why a particular bit of code would not compile he felt the error message seemed less than helpful: &#8220;CRghtColr As Color = Color.RGBA(000,061,255,208)&#8221;.</p>
<p><span id="more-3869"></span></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3870" src="https://blog.xojo.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-03-at-4.15.25-PM.png" alt="" width="946" height="456" /></p>
<p>CRightColr is set up as a shared color property. And the person wanted the default value to be set from the Color.RGBA function. When you try this you get an error.</p>
<pre style="padding-left: 30px;">Window1.CRghtColr Declaration
Not enough arguments: got 0, expected 4.
Private Shared CRghtColr As Color = Color.RGBA(000, 061, 255, 208)</pre>
<p>It&#8217;s confusing as it&#8217;s not clear what requires more parameters. However, the <a href="http://developer.xojo.com/userguide/modules$adding-constants">User Guide</a> quite clearly states that <em>Constants can be assigned only a literal value, another constant value or the result of a constant expression.</em></p>
<p>A literal is easy &#8211; it&#8217;s something like &amp;cFF00FF00 &#8211; a color literal. A constant value would be assigning one constant to another. Say you had another constant:</p>
<pre style="padding-left: 30px;"> cColor as color = &amp;cffffff00</pre>
<p>You could then assign:</p>
<pre style="padding-left: 30px;">Private Shared CRghtColr As Color = cColor
</pre>
<p>And this would be fine.</p>
<p>A &#8220;constant expression&#8221; is a little less obvious here. It&#8217;s literally an expression made up only of constant values. This example should make it clearer:</p>
<pre style="padding-left: 30px;">Const constant1 as integer = 90
Const constant2 as integer = 100
Const constant3 as integer = constant1 + constant2 // constant1 + constant2 is a constant expression
</pre>
<p>Note that none of the allowable ways to set a constant include calling a function like Color.RGBA. Unfortunately while the compiler tries its best to make sense of what you&#8217;re trying to do, this one confuses it and you get this somewhat unhelpful error message.</p>
<p>So, if you ever happen to see this, check to see that you are following the rules about what is allowed for the default value of a constant.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
