Dan Muey wrote:

> In addtion to Rob's very sound advice it sound like you simply need an array:
>
> my @enum = qw(dhbold dhcaption dhend dhform);
>
> print $enum[0]; # prints dhbold
> print $enum[2]; # prints dbhend
>
> HTH
>
> DMuey

Sorry Dan,

I dn't think so.  That usage actually goes in the wrong direction for at least
purpose of any enum.  An array of this sort requires the knowledge of magic
numbers to yield a meaningful string.  The purpose of an enum is at least
partially to allow the use of meaningful text to refer to a constant numerical
value.  The primary purpose, as with any symbolic constant, is centralization of
updates.  Enums also limit the possible values assigned to a variable of an enum
type to those enumerated, also.

FWIW, the VB IDE has some neat, if sometimes annoying, features that accompany
enums.  Once declared, an enum becomes part of the IDE's knowledge base.  In
assignment statements with a variable of a declared enum type as the lvalue, the
system presents a list of valid values:
...
[Jes a sec, here, whilst I blow the cobwebs off and fire up VB.]
...

In AppDefs.bas:


Public Enum ACCOUNT_TYPE
   ASSET = 1
   LIABILITY = 2
   EQUITY = 3
   REVENUE = 4
   EXPENSE = 5
   DIVIDEND = 6
   CONTRA_ASSET = 11
End Enum

Public Function EffectOnAccount(udtColumn As LedgerSide, _
AcctClass As ACCOUNT_TYPE) As AccountImpact
' Called by:   notRightForDebit
'              notRightForCredit
'              PolarizeBalancexByAccountType
   Select Case AcctClass
      Case LIABILITY, REVENUE, CONTRA_ASSET, EQUITY
         Select Case udtColumn
            Case DEBIT_SIDE
               EffectOnAccount = DECREASE_BALANCE
            Case CREDIT_SIDE
               EffectOnAccount = INCREASE_BALANCE
         End Select
      Case ASSET, EXPENSE, DIVIDEND
         Select Case udtColumn
            Case DEBIT_SIDE
               EffectOnAccount = INCREASE_BALANCE
            Case CREDIT_SIDE
               EffectOnAccount = DECREASE_BALANCE
         End Select
   End Select
End Function

You wouldn't believe how little typing I had to do to write this.:
The Private and Function keywords, function name, and open paren
The parameter names, 'As' keywords, commas, and close paren.
newlines
comments
Conrol lines and End statements for the select statements
Case keywords, spaces, and commas

i.e. the things that an editor can not possibly know without being told.

In cases where the system can have self-knowledge, such as types available for
declarations, values appropriate for any enumerated type, members of 'Type' [aka
C struct] structures--the editor provides a list that I can pick and click from.
That is one advatage of typed languages, in that they can support the use of AI
in code editing.


As convenient as all this is, though, I've gotta say:  Perl is a hell of a lot
more fun.  (;-o)

Joseph






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to