Results 1 to 7 of 7

Thread: Enum-and this does what?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Location
    Rhode Island, USA
    Posts
    29

    Enum-and this does what?

    I was reading over some code i came across on one of these forums, and was wondering what enum is? or public enum "variable". could someone please explain this to me? thanks

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Do you mean what is the definition of the term "enumeration"? That's a hard-coded list of values. A lot of the time it will be used to put human-language names to things like binary numbers, e.g. the MsgBoxStyle enumeration:
    ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vamscMsgBoxConstants.htm

    each of the listings in the enumeration points to a numerical value - so you have the convenience of human-readable names for values at development time, but the efficiency of a number at build time.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Location
    Rhode Island, USA
    Posts
    29

    def. & coding use

    thanks for the defintion, that shed some light, but i was wondering what you would use that in code for and for what purpose. could you possibly supply an example? thanks man

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Enums generally supply a fixed list of choices. The icons or button choices are an enum when you use the Msgbox. Here is another example:

    VB Code:
    1. Public Class EnumExample
    2.  
    3.   Public Enum LoadByOptions
    4.      ByName
    5.      BySSN
    6.      ByID
    7.   End Enum
    8.  
    9.   Public Sub Load(ByVal LoadBy As LoadByOptions)
    10.     Select Case LoadBy
    11.        Case LoadByOptions.ByName
    12.  
    13.        Case LoadByOptions.BySSN
    14.  
    15.        Case LoadByOptions.ByID
    16.  
    17.     End Select
    18.   End Sub
    19.  
    20. End Class

    The use of enums here makes it much easier than using a numbered list (i.e. 1, 2, 3) and easier to read since instead of numbers you have what they represent (ByName, SSN, or ID).

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I'm glad someone asked this, because today I have just thought about implementing one...

    Here's the drill:

    Customer payments.... how did they pay? Visa, Check, Cash, Discover, MasterCard, American Express?

    Sounds like a great application of the enum class....

    VB Code:
    1. Private pType As PayMentType
    2.  
    3.     Public Enum PayMentType
    4.         Visa = 0
    5.         Mastercard = 1
    6.         Discover = 2
    7.         AmericanExpress = 3
    8.         Cash = 4
    9.         Check = 5
    10.     End Enum
    11.  
    12.     Public Property Method(ByVal aPaymntType As PayMentType) As PayMentType
    13.  
    14.         Get
    15.             Return pType
    16.         End Get
    17.         Set(ByVal Value As PayMentType)
    18.             pType = Value
    19.         End Set
    20.  
    21.     End Property

    VB Code:
    1. Dim r As New Payment()
    2.         r.Method = Payment.PayMentType.AmericanExpress

    Of course I'm still debating whether I should even hardcode payment types in.... if a new type of credit card comes out in 2 years.. I might get some calls...

  6. #6
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    from my experience you should hard code as little as possible so I wouldn't if i was you! It'll only create more work for you at a later date!
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    yea... but since this is a custom project... and the numskels wouldn't be able to figure out how to update a database, I think I'm going to have to hardcode it...

    Hard-coded or not, if these change, I'll have to make a trip back... and adding a new enumeration type and a new button that represents that type would take all of 1 minute.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width