Results 1 to 4 of 4

Thread: [RESOLVED] Return Description from Enum List

  1. #1

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Resolved [RESOLVED] Return Description from Enum List

    Hi all
    I have a user-defined class question. In my class I use an enumerated list for product type. I can read and write this value to an instance of the class.
    What I need to do now is read the string value for the instance from the enumerated list.

    Here's what I have so far.
    The ProdDesc property should, for example, retun a value of "Desktop" when privProdType = 1.
    I'm hoping I can do this without using a SELECT CASE syntax. (The Product list is much longer in real life.

    VB Code:
    1. Dim privProdType As Product
    2.  
    3. Public Enum Product
    4.     Desktop = 1
    5.     Notebook = 2
    6.     Server = 3
    7.     Printer = 4
    8.     'etc, etc
    9. End Enum
    10.  
    11. Public Property Let ProdType(newType As Product)
    12.     privProdType = newType
    13. End Property
    14.  
    15. Public Property Get ProdType() As Product
    16.     ProdType = privProdType
    17. End Property
    18.  
    19. Public Property Get ProdDesc() As String
    20.     'some code to get the desc from the Enum list - based on privProdType
    21. End Property
    Last edited by DKenny; Dec 15th, 2005 at 11:31 AM.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Return Description from Enum List

    AFAIK, a Select Case is the best option

    The good news is that MZTools (link in my sig) can create all the Cases for you.

  3. #3
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Return Description from Enum List

    If you use a Dictionary, you can:

    Function Keys()
    Member of Scripting.Dictionary
    Get an array containing all keys in the dictionary.


    You can also:

    Function Items()
    Member of Scripting.Dictionary
    Get an array containing all items in the dictionary.


    I find Dictionaries very useful. You draw your own conclusions.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  4. #4

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Return Description from Enum List

    Dictioary looks like the way to go.

    Thanks Webtest
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

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