<?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>Enumeration &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/enumeration/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Mon, 27 Sep 2021 17:31:03 +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>How a Binary Enum Simplifies a Calendar Week Day Selector</title>
		<link>https://blog.xojo.com/2021/09/28/how-a-binary-enum-simplifies-a-calendar-week-day-selector/</link>
		
		<dc:creator><![CDATA[Wayne Golding]]></dc:creator>
		<pubDate>Tue, 28 Sep 2021 13:00:00 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9332</guid>

					<description><![CDATA[In Xojo 2021R2 binary enumerations were introduced. These Enums must be declared in a module and are treated by the compiler as a class. Learn to create an Enum for Days of the Week and demonstrate the use of that by creating a custom segmented button control.]]></description>
										<content:encoded><![CDATA[
<p>In Xojo 2021R2 binary enumerations were introduced.&nbsp;These Enums must be declared in a module and are treated by the compiler as a class.&nbsp;Xojo documentation for Enums can be found at <a href="http://documentation.xojo.com/api/data_types/enumeration.html">Enumeration &#8211; Xojo Documentation</a>.</p>



<p>I&#8217;d like to show you how to create an Enum for Days of the Week and demonstrate the use of that by creating a custom segmented button control.</p>



<p>Open Xojo and create a new Desktop Project.&nbsp; Insert a module and give it a name – I called mine Enumerations.</p>



<figure class="wp-block-image size-full is-style-default"><img fetchpriority="high" decoding="async" width="384" height="222" src="https://blog.xojo.com/wp-content/uploads/2021/09/image.png" alt="" class="wp-image-9335" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image.png 384w, https://blog.xojo.com/wp-content/uploads/2021/09/image-300x173.png 300w" sizes="(max-width: 384px) 100vw, 384px" /></figure>



<p>Next, add an enumeration.</p>



<figure class="wp-block-image size-full is-style-default"><img decoding="async" width="514" height="624" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-1.png" alt="" class="wp-image-9336" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-1.png 514w, https://blog.xojo.com/wp-content/uploads/2021/09/image-1-247x300.png 247w" sizes="(max-width: 514px) 100vw, 514px" /></figure>



<p>Call this Enum DaysOfWeek and make it a binary enum.</p>



<figure class="wp-block-image size-full is-style-default"><img decoding="async" width="322" height="208" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-2.png" alt="" class="wp-image-9337" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-2.png 322w, https://blog.xojo.com/wp-content/uploads/2021/09/image-2-300x194.png 300w" sizes="(max-width: 322px) 100vw, 322px" /></figure>



<p>Next, fill in the Declarations.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="270" height="376" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-3.png" alt="" class="wp-image-9338" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-3.png 270w, https://blog.xojo.com/wp-content/uploads/2021/09/image-3-215x300.png 215w" sizes="auto, (max-width: 270px) 100vw, 270px" /></figure>



<p>Next, I’m going to add a bunch of Constants to the module, one for each day of the week.&nbsp; This will allow me to localise the control later.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="358" height="276" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-4.png" alt="" class="wp-image-9339" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-4.png 358w, https://blog.xojo.com/wp-content/uploads/2021/09/image-4-300x231.png 300w" sizes="auto, (max-width: 358px) 100vw, 358px" /></figure>



<p>Now I’ll add a convenience method called ToString that will extend the DaysOfWeek Enum.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="382" height="338" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-5.png" alt="" class="wp-image-9340" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-5.png 382w, https://blog.xojo.com/wp-content/uploads/2021/09/image-5-300x265.png 300w" sizes="auto, (max-width: 382px) 100vw, 382px" /></figure>



<p>The code in this method is:</p>



<pre class="wp-block-preformatted">Var SelectedDays() As String

Var d As DaysOfWeek

d = DaysOfWeek.Sunday
If Value.Contains(d) Then
  SelectedDays.Add(Day1)
End If

d = DaysOfWeek.Monday
If Value.Contains(d) Then
  SelectedDays.Add(Day2)
End If

d = DaysOfWeek.Tuesday
If Value.Contains(d) Then
  SelectedDays.Add(Day3)
End If

d = DaysOfWeek.Wednesday
If Value.Contains(d) Then
  SelectedDays.Add(Day4)
End If

d = DaysOfWeek.Thursday
If Value.Contains(d) Then
  SelectedDays.Add(Day5)
End If

d = DaysOfWeek.Friday
If Value.Contains(d) Then
  SelectedDays.Add(Day6)
End If

d = DaysOfWeek.Saturday
If Value.Contains(d) Then
  SelectedDays.Add(Day7)
End If

Return String.FromArray(SelectedDays, ", ")</pre>



<p>You can see from this code that it is possible to include multiple days in this Enum.&nbsp; The return string might be “Sunday, Monday, Friday” for example.</p>



<p>Create the DaysOfWeek Control by dragging a segmented button from the library to the navigator and naming it DaysOfWeekControl.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="292" height="62" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-6.png" alt="" class="wp-image-9341"/></figure>



<p>Then use the Inspector Behaviour option to customise the control.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="592" height="700" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-7.png" alt="" class="wp-image-9342" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-7.png 592w, https://blog.xojo.com/wp-content/uploads/2021/09/image-7-254x300.png 254w" sizes="auto, (max-width: 592px) 100vw, 592px" /></figure>



<p>Change the default width to 500 and the selection style to 1 for multiple</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="790" height="700" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-8.png" alt="" class="wp-image-9343" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-8.png 790w, https://blog.xojo.com/wp-content/uploads/2021/09/image-8-300x266.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-8-768x681.png 768w" sizes="auto, (max-width: 790px) 100vw, 790px" /></figure>



<p>Unfortunately, we can’t edit the segments here as the control is a textfield, not a textarea and the edit button is missing.&nbsp; But we can edit the source file (you need a license capable of saving the project in text format).&nbsp; Save and close the project, and open the DaysOfWeekControl.xojo_code file in Notepad, search for “One” which will find the initial value of the control.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="360" height="34" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-15.png" alt="" class="wp-image-9351" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-15.png 360w, https://blog.xojo.com/wp-content/uploads/2021/09/image-15-300x28.png 300w" sizes="auto, (max-width: 360px) 100vw, 360px" /></figure>



<p>You can see each segment is separated with “\r” which the IDE translates to &lt;CR&gt;.&nbsp; Replace &#8220;One\rTwo&#8221; with &#8220;#Day1\r#Day2\r#Day3\r#Day4\r#Day5\r#Day6\r#Day7&#8221; which will tell the compiler to use the localised Day constants created earlier.&nbsp;Save the code file and reopen the project.</p>



<p>Now we can continue customising the control first adding a computed property Value As DaysOfWeek. In the Get method add this code:</p>



<pre class="wp-block-preformatted">Var Result As DaysOfWeek = 0 ' The default value is set to create an instance of Result
For i As Integer = 0 To 6 ' Each Segment in the control
  If me.SegmentAt(i).Selected Then
    Var d As DaysOfWeek = 2 ^ i ' Converts the index (i) to the binary number that matches the value of the enum
    Result = Result Or d ' Adds the selected day to the enum
  End If
Next i

Return Result</pre>



<p>You’ll notice the first line sets the value of Result to 0, this is important as otherwise the variable will be Nil – remember this is being rendered as a class by the compiler.</p>



<p>In the Set Method place this code:</p>



<pre class="wp-block-preformatted">For i As Integer = 0 To 6 ' Index of each segment
&nbsp; Var d As DaysOfWeek = 2 ^ i ' Convert the index (i) to binary
&nbsp; me.SegmentAt(i).Selected = value.Contains(d) ' Set the selected state of the button
Next i

RaiseEvent ValueChanged(value)</pre>



<p>This will show the button as pressed or not depending on whether the day is included on the value.&nbsp; Now add an event definition.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="358" height="288" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-9.png" alt="" class="wp-image-9344" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-9.png 358w, https://blog.xojo.com/wp-content/uploads/2021/09/image-9-300x241.png 300w" sizes="auto, (max-width: 358px) 100vw, 358px" /></figure>



<p>Which will raise when a button is pressed, which means we need to handle the pressed event of the control.</p>



<pre class="wp-block-preformatted">Sub Pressed(segmentIndex as integer) Handles Pressed
&nbsp; #Pragma Unused segmentIndex

&nbsp; RaiseEvent ValueChanged(Value)
&nbsp;End Sub</pre>



<p>Time to use the control.&nbsp;We want to place a copy of the control onto Window1; we can either drag the control from the Navigator or select it from the Library (it will show in the Project Controls section).&nbsp;I’m also going to add a label to the Window under the DaysofWeek control, name it SelectedDaysLabel and make it the same width as the control (500).&nbsp;This will be where we will show the result of the days selected.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="818" height="210" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-10.png" alt="" class="wp-image-9345" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-10.png 818w, https://blog.xojo.com/wp-content/uploads/2021/09/image-10-300x77.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-10-768x197.png 768w" sizes="auto, (max-width: 818px) 100vw, 818px" /></figure>



<p>Next, handle the ValueChanged event on the control:</p>



<pre class="wp-block-preformatted">Sub ValueChanged(Value As DaysOfWeek) Handles ValueChanged<br>&nbsp; SelectedDaysLabel.Text = Value.ToString<br>End Sub</pre>



<p>When we run the project and select some days, we’ll see something similar to the following.</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="796" height="174" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-11.png" alt="" class="wp-image-9346" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-11.png 796w, https://blog.xojo.com/wp-content/uploads/2021/09/image-11-300x66.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-11-768x168.png 768w" sizes="auto, (max-width: 796px) 100vw, 796px" /></figure>



<p>Now to show the power of the binary enum I’m going to add another declaration to the Enumeration “WeekDays” with a value of 62</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="238" height="410" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-12.png" alt="" class="wp-image-9347" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-12.png 238w, https://blog.xojo.com/wp-content/uploads/2021/09/image-12-174x300.png 174w" sizes="auto, (max-width: 238px) 100vw, 238px" /></figure>



<p>62 is the total of the values for Monday through Friday.&nbsp;Once we have this, we can add a button to the window and set its “Pressed” event handler to:</p>



<pre class="wp-block-preformatted">Sub Pressed() Handles Pressed<br>&nbsp; DaysOfWeekControl1.Value = DaysOfWeek.Weekdays<br>End Sub</pre>



<p>Pressing the button will result in:</p>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="808" height="226" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-13.png" alt="" class="wp-image-9348" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-13.png 808w, https://blog.xojo.com/wp-content/uploads/2021/09/image-13-300x84.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-13-768x215.png 768w" sizes="auto, (max-width: 808px) 100vw, 808px" /></figure>



<p>Taking this further we can add the enum value to the DateTime class by adding another Extension method to the module as below.</p>



<pre class="wp-block-preformatted">Public Function DayOfWeekEnum(Extends Value As DateTime) As DaysOfWeek&nbsp; 

  Var Result As DaysOfWeek = 2 ^ (Value.DayOfWeek - 1)
&nbsp; Return Result

End Function</pre>



<p>We need to subtract 1 from the DayOfWeek property of the passed DateTime object as the days are 1 based not 0 as in the control.&nbsp;To demonstrate how this works I’m going to add a multiline label to the window called SelectedDatesLabel and set that to show which dates over the next week have been selected by updating the ValueChanged handler as below:</p>



<pre class="wp-block-preformatted">Sub ValueChanged(Value As DaysOfWeek) Handles ValueChanged

SelectedDaysLabel.Text = Value.ToString

SelectedDatesLabel.Text = ""

For i As Integer = 1 To 7 ' From tomorrow for a week
 Var dt As DateTime = DateTime.Now.AddInterval(0, 0, i)
 If Value.Contains(dt.DayOfWeekEnum) Then
  SelectedDatesLabel.Text = SelectedDatesLabel.Text + _
  dt.ToString(DateTime.FormatStyles.Short, DateTime.FormatStyles.None) _
  + EndOfLine
    End If
  Next i

End Sub</pre>



<figure class="wp-block-image size-full is-style-default"><img loading="lazy" decoding="async" width="810" height="394" src="https://blog.xojo.com/wp-content/uploads/2021/09/image-14.png" alt="" class="wp-image-9349" srcset="https://blog.xojo.com/wp-content/uploads/2021/09/image-14.png 810w, https://blog.xojo.com/wp-content/uploads/2021/09/image-14-300x146.png 300w, https://blog.xojo.com/wp-content/uploads/2021/09/image-14-768x374.png 768w" sizes="auto, (max-width: 810px) 100vw, 810px" /></figure>



<p>That’s it folks, hope you enjoyed this tutorial.</p>



<p><em>Wayne Golding has been a Xojo developer since 2005 and is a Xojo MVP. He operates the IT Company <a href="http://www.axisdirect.nz">Axis Direct Ltd </a>which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayne’s hobby is robotics where he uses Xojo to build applications for his Raspberry Pi, often implementing IoT for remote control.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Enumeration Enhancements</title>
		<link>https://blog.xojo.com/2021/07/22/enumeration-enhancements/</link>
		
		<dc:creator><![CDATA[Greg O'Lone]]></dc:creator>
		<pubDate>Thu, 22 Jul 2021 11:48:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[IDE]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8855</guid>

					<description><![CDATA[Xojo 2021r2 introduces a couple of enhancements to Enumerations in Xojo. The enumeration editor now shows a preview of what the value will be so there's no more guessing or counting. In addition, we've added a new Binary option which allows you to automatically create sets that aren't mutually exclusive. ]]></description>
										<content:encoded><![CDATA[
<p>Xojo 2021r2 introduces a couple of enhancements to <a href="https://documentation.xojo.com/getting_started/using_the_xojo_language/enumerations.html">enumerations</a> in Xojo. The enumeration editor now shows a preview of what the value will be so there&#8217;s no more guessing or counting.</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2021/07/image-1.png" alt="" class="wp-image-8857" width="156" height="240" srcset="https://blog.xojo.com/wp-content/uploads/2021/07/image-1.png 276w, https://blog.xojo.com/wp-content/uploads/2021/07/image-1-195x300.png 195w" sizes="auto, (max-width: 156px) 100vw, 156px" /><figcaption>Example of Enumeration with default values showing</figcaption></figure></div>



<p>In addition, we&#8217;ve added a new Binary option which allows you to automatically create sets that aren&#8217;t mutually exclusive. That is, the values of the elements are automatically powers of two and can have binary operations applied to them:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2021/07/image-3.png" alt="" class="wp-image-8859" width="162" height="236" srcset="https://blog.xojo.com/wp-content/uploads/2021/07/image-3.png 284w, https://blog.xojo.com/wp-content/uploads/2021/07/image-3-206x300.png 206w" sizes="auto, (max-width: 162px) 100vw, 162px" /><figcaption>Example of Binary Enumeration default values</figcaption></figure></div>



<p>This new feature comes with the requirement that they be placed inside a Module because they&#8217;re rendered into your project as a Class. The reason for this is that these classes automatically have some helper methods on them to make working with the binary data easier.</p>



<ul class="wp-block-list"><li>An Operator_Convert which takes an Integer:<br><code>Var x as MyEnum = 3 // MyEnum.George, MyEnum.John</code><br></li><li>&#8230;as well as one that returns an integer:<br><code>Var y as Integer = MyEnum.George // y = 2</code><br></li><li>Automatic conversion to and from Integer:<br><code>Var x as Integer = MyEnum.Ringo // x = 4</code><br></li><li>Binary operations And, Or and Xor:<br><code>Var x as MyEnum = MyEnum.Paul Or MyEnum.Mary // x has a value of 40</code><br></li><li>Equality operations so you can compare the internal value of one instance to another:<br><code>Var x as MyEnum = MyEnum.Paul<br>Var y as MyEnum = MyEnum.Ringo<br>If x = y Then</code><br></li><li>Contains helper method:<br><code>If x.Contains(MyEnum.Peter) Then</code><br></li><li>A Read-Only Value property so you can see the internal value in the debugger</li></ul>



<p>Just like regular Enumerations, the editor also allows you to explicitly specify the value of an element:</p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img loading="lazy" decoding="async" src="https://blog.xojo.com/wp-content/uploads/2021/07/image-5.png" alt="" class="wp-image-8862" width="157" height="226" srcset="https://blog.xojo.com/wp-content/uploads/2021/07/image-5.png 338w, https://blog.xojo.com/wp-content/uploads/2021/07/image-5-209x300.png 209w" sizes="auto, (max-width: 157px) 100vw, 157px" /></figure></div>



<p>This is so instead of having to write: <br><code>Var x as MyEnum = MyEnum.George Or MyEnum.John Or MyEnum.Ringo Or MyEnum.Paul</code><br><br>You can simply write:<br><code>Var x as MyEnum = MyEnum.TheBeatles</code><br><br>We hope that you&#8217;ll enjoy this feature as much as we do!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Secrets of the Enumeration Editor</title>
		<link>https://blog.xojo.com/2020/05/14/secrets-of-the-enumeration-editor/</link>
		
		<dc:creator><![CDATA[Robin Lauryssen-Mitchell]]></dc:creator>
		<pubDate>Thu, 14 May 2020 17:21:00 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6992</guid>

					<description><![CDATA[Depending on your style of coding the Enumeration Editor might be used regularly or not a lot. But, either way it probably contains a secret or two waiting for you.]]></description>
										<content:encoded><![CDATA[
<p>Depending on your style of coding the <a href="https://documentation.xojo.com/getting_started/using_the_ide/enumeration_editor.html">Enumeration Editor</a> might be used regularly or not a lot. But, either way it probably contains a secret or two waiting for you.</p>



<p><strong>Keyboard</strong><br>The Tab key steps to the next enumeration line. Tabbing off the last enumeration lands on the blank ‘+’ line. Unfortunately pressing Return does not open the enumeration line editor (hmm, Feature Request!). Tabbing off the blank ‘+’ lands on the enumeration editor ‘Name’ field.</p>



<p>Shift-Tab steps to the previous enumeration line. Tabbing off the first enumeration line lands on the enumeration declaration in the Navigator.</p>



<p><strong>Reordering</strong><br>Existing enumerations can be reordered. Using the mouse, grab the line to be moved, drag it to the desired location in the enumeration list and release. Do not try grabbing the ‘-‘ symbol!</p>



<p><strong>Assignments</strong><br>A value can be assigned to an enumeration label. After the label type ‘=’ and an integer value. For example: ‘foo = 123’. Spaces around the assignment symbol (‘=’) are optional. </p>



<p><em>Note: ‘foo =’ will generate a syntax error.</em></p>



<p><strong>Non-sequential values<br></strong>Values assigned to enumeration labels do not have to be sequential. For example: </p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<p style="padding-left: 40px;"> one = 3<br>two = 2<br>three = 1 </p>
</div></div>



<p><em>Note: Same value assignments are legal, so ‘one’ and ‘two’ could be assigned the same value, e.g. 3.</em></p>



<p><strong>Non-ordered values<br></strong>Values assigned to enumeration labels do have to be ordered. For example: </p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<p style="padding-left: 40px;">one = 2<br data-rich-text-line-break="true">two = 16<br data-rich-text-line-break="true">three = 1</p>
</div></div>



<p><strong>Assigned and unassigned enumerations<br></strong>If assigned and unassigned enumerations are intermixed, the unassigned enumeration will be assigned the last assigned value + 1. For example: </p>



<p style="padding-left: 40px;"> one = 16<br>two<br>three = -2<br>four<br>five = 3<br>six <br><br>

will render as:<br><br>one = 16<br>two = 17<br>three = -2<br>
four = -1<br>
five = 3<br>
six = 4 </p>



<p><strong>Comments</strong><br>Enumeration lines can contain comments. For example: </p>


<p style="padding-left: 40px;">one = 16 &nbsp;//This is a comment</p>


<p>Any of the valid Xojo comment symbols are allowed, I just prefer ‘//’.</p>



<p><strong>Base type</strong><br>The default base type for an enumeration is Integer. It can be any integer type. For example: int32<br>One of my favourites is uint8. But you need to be aware of a couple of things. In the following example, the enumeration is ‘Foos’ and the base type is uint8:</p>



Foos(uint8): <br><p style="padding-left: 40px;"> one =-2 <br> two<br>three<br>four<br>five = 17<br>six </p>



<p>will render as:</p>



<p style="padding-left: 40px;"> one = 254 //value wrapped around the base type range<br>two = 255 <br> three = 0<br>four = 1<br>five = 17<br>six = 18//Incremented from the previous value </p>



<p>If converting the enumeration to an integer the same base type bit-width must be used.<br>For example:&nbsp;thisValue as int32 = uint8(Foos.two)</p>



<p style="padding-left: 40px;"> or: thisValue as int32 = int8(Foos.two)</p>



<p>I try to stick to using the same enumeration base type. It avoids confusion caused by type range wrap-around.</p>



<p><strong>Enumeration value references<br></strong>An enumeration value can be assigned an enumeration label from another enumeration declaration. For example, given one enumeration is declared as ‘Foos’ and there is another enumeration declared as ‘Things’. In the following example ‘Things’ is attached to a module or class called ‘Those’.</p>



<p style="padding-left: 40px;">Those.Things(integer): <br> thing1 = 1 <br> thing2 = -2 </p>



Foos(uint8):<br><p style="padding-left: 40px;"> one = 1<br> two = Foos.four<br>three = Those.Things.thing2<br>four = Foos.three </p>



Foos will render as:<br> <p style="padding-left: 40px;"> one = 1<br>two = 254 //Clever compiler&nbsp;<br>three = 254 //Remember base type wrap-around<br>four = 254</p>



<p><em>Note: The compiler will catch recursive declarations!</em></p>



<p>Constant references are also allowed. For example:</p>



<p style="padding-left: 40px;">THING = 127 </p>



Foos(uint8):<br> <p style="padding-left: 40px;">         one = THING </p>



will render as:  <p style="padding-left: 40px;"> one = 127 </ p>



<p><strong>Current limitations<br></strong>a) Non-integer base types are not allowed, e.g. String or Double</p>



<p>b) &nbsp;Enumeration values cannot be expressions, e.g. 2+3 is not allowed <em>Hint: Another secret, <a href="https://documentation.xojo.com/getting_started/using_the_ide/inspector.html#Numeric_Properties">some fields in the IDE do allow simple expressions</a>.</em></p>



<p>c) &nbsp;The maximum number of enumeration elements is uint64[Max]. If that is a limitation, then your code probably has other problems!</p>



<p>d) &nbsp;An enumeration argument is not rigorously checked against its declaration when passed as a function or method parameter. For example:</p>



<pre class="wp-block-preformatted">Foos(int32)
one = 1
two = 2

sub Test(value as Foos)
  dim thisValue as int32 = int32(value)
end sub

Test(Foos(5))</pre>



<p>Would result in ‘thisValue’ having the value 5. Interestingly the Debugger will show the value ‘5’ in red, so something can detect invalid values.</p>



<p>e) &nbsp;The enumeration editor font is not affected by the Options/Preferences,Code Editor, Font selection.</p>



<p>I hope there were at a least of couple of things in here you did not know before. I&#8217;m not sure if any of this makes the Enumeration Editor any easier to use, but it might make it a little more fun. Enjoy!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
