Results 1 to 6 of 6

Thread: Enum Types

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Enum Types

    Can i get the name of the elements not the values?
    Code:
    Private Enum myName
        Alex = 1
        Bert = 2
        Charlie = 3
        Danny = 4
        Evan = 5
    End Enum
    I want to list down the names not the values.

    Thanks

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Enum Types

    Another question, can i change the values of enum types during runtime?

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Enum Types

    This might be the only way to return the name of the Enum, taken from the FAQ here.

    vb Code:
    1. Dim MyVariable As MyValues
    2.   MyVariable = First
    3.  
    4.   If MyVariable = Second Then
    5.      MsgBox "This message will not be shown!"
    6.   End If

    That is you would use it like

    vb Code:
    1. Private Enum myName
    2.     Alex = 1
    3.     Bert = 2
    4.     Charlie = 3
    5.     Danny = 4
    6.     Evan = 5
    7. End Enum
    8.  
    9. Private Sub Form_Load()
    10. Dim MyVariable As myName
    11.   MyVariable = Danny
    12.  
    13.   If  MyVariable = Danny Then
    14.      MsgBox "Danny"
    15.   End If
    16. End Sub
    Last edited by Nightwalker83; Nov 6th, 2011 at 02:19 AM. Reason: Fixed spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Enum Types

    I think OP is trying to use the Enum in 'reverse'.

    eg MyVariable = 4 and the MessageBox outputting 'Danny' - which is not what Enums do. Only way I can think of is to have a 'look-up Table' (eg an Array with the appropriate names in appropriate elements)

    MsgBox strNames(myVariable)
    Last edited by Doogle; Nov 6th, 2011 at 02:26 AM.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Enum Types

    Quote Originally Posted by Doogle View Post
    I think OP is trying to use the Enum in 'reverse'. ... Only way I can think of is to have a 'look-up Table'
    Agreed. And to the other question the OP asked, no, you cannot change the values during run-time. Enumerations are constant
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Enum Types

    Thanks All.

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