Results 1 to 4 of 4

Thread: [RESOLVED] Getting Enum value based on string

  1. #1

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Resolved [RESOLVED] Getting Enum value based on string

    I'm still searching, but there's a crap load of posts with "enum" and "value" in it... so I'm posting this as a short cut while I still attempt to search.

    Short description: I have a file that will have a field where the value will be "string" or "date" or "number" ... I need to translate these into an enum type:
    Company.NameSpace.Assembly.DataTypes.String
    Company.NameSpace.Assembly.DataTypes.Date
    Company.NameSpace.Assembly.DataTypes.Number
    Company.NameSpace.Assembly.DataTypes.Boolean
    and so on... so that I can pass it to another method that's expecting the enumeration value as a parameter.

    I know there's a way to go from the value to get to the "text" of the enum... is there a way to go the other way?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  2. #2

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Getting Enum value based on string

    Apparently I just needed to be a little more patient...
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: [RESOLVED] Getting Enum value based on string

    try this

    Code:
    Dim myEnum as Company.NameSpace.Assembly.DataTypes = DirectCast([Enum].Parse(GetType(Company.NameSpace.Assembly.DataTypes), "String"), Company.NameSpace.Assembly.DataTypes)
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  4. #4

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Getting Enum value based on string

    Indeed! That's basically what I ended up with... Stupid thing is that this isn't the first time I've done this... snaaaarf!

    It also turns out that we're treating everything like a string when we first import it, so I didn't even need to worry about the type.... grumble grumble grumble...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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