Propeller Manual

Table Of Contents
CON – Spin Language Reference
cases, the values themselves don’t usually matter; all that matters is that they are each
assigned a unique number. Defining enumerated values like this has the advantages of
insuring that the assigned values are unique and contiguous within the group.
Using the example above, the methods that use them can do things like the following (assume
Mode is a symbol set by a calling object):
case Mode
RunTest : <test code here>
RunVerbose : <verbose code here>
RunBrief : <brief code here>
RunFull : <full code here>
—or—
if Mode > RunVerbose
<brief and run mode code here>
Notice that these routines do not rely on the exact value of the mode, but rather they rely on
the enumerated mode symbol itself for comparisons as well as the position of the symbol in
relation to other symbols in the same enumeration. It is important to write code this way to
decrease potentials for bugs introduced by future changes.
Enumerations don’t have to consist of comma-separated items either. The following also
works and leaves room for right-side comments about each mode.
CON 'Declare modes of operation
#0
RunTest 'Run in test mode
RunVerbose 'Run in verbose mode
RunBrief 'Run with brief prompts
RunFull 'Run in full production mode
The above example does the same thing as the previous in-line example, but now we have
convenient room to describe the purpose of each mode without losing the automatic
incrementing advantage. Later on, if there’s a need to add a fifth mode, simply add it to the
list in whatever position is necessary. If there is a need for the list to begin at a certain value,
simply change the
#0 to whatever you need: #1, #20, etc.
It is even possible to modify the enumerated value in the middle of the list.
CON
'Declare modes of operation
#1, RunTest, RunVerbose, #5, RunBrief, RunFull
Page 88 · Propeller Manual v1.1