Results 1 to 4 of 4

Thread: How to convert string to enum in vb.net application

  1. #1
    Join Date
    Feb 2009
    Posts
    71

    How to convert string to enum in vb.net application

    I am working on .Net application Can anyone suggest me how do I convert the string into an enum or an vice a versa, this is because I've come across the situation on a number of occasions when coding where I've wanted to convert from a string to an enum but unable to do that.

  2. #2
    Join Date
    Jan 2009
    Posts
    140

    Re: How to convert string to enum in vb.net application

    Enums are a powerful construction in C# and other programming languages I will provide you the little hint about how to go further, if you are on the right track and proper understanding of VB.Net then you should get an idea about how to start for your application, and if not then let me know i will give more clues to you.

    object Enum.Parse(System.Type enumType, string value, bool ignoreCase);

  3. #3
    Join Date
    Dec 2008
    Posts
    161

    Re: How to convert string to enum in vb.net application

    Are you building a great new web application? Another more flexible approach (albeit much slower) is to adhorn each Enum value with a DescriptionAttribute, and to use reflection to grab that, <span style="background-color:yellow;">this text would have a yellow background</span> I perfer HTML over scripting because HTML is a bit easier to understand a lot of the time, but I wouldn't just blow this off because it can have some advantages some of the time

  4. #4
    Join Date
    Dec 2008
    Posts
    161

    Re: How to convert string to enum in vb.net application

    Pass the string value equivalent to the value in the enum. You might want to put a try..catch around the TryParse method in case a value not in the enum is provided, when you are working with finite sets such as fruits, days of the week or colors. Visual Studio's Intellisense is very nice with Enums because it lists all the options for the programmer to choose from.

Similar Threads

  1. Convert string into int in C
    By screwball in forum Software Development
    Replies: 4
    Last Post: 22-12-2011, 08:47 PM
  2. Convert XML string into DOM
    By GreatThinker in forum Software Development
    Replies: 6
    Last Post: 22-07-2010, 09:48 AM
  3. Convert String to filename
    By Maya Angelou in forum Software Development
    Replies: 5
    Last Post: 12-03-2010, 01:20 PM
  4. How to convert string to float c#
    By Pratyush in forum Software Development
    Replies: 3
    Last Post: 14-08-2009, 01:09 PM
  5. How to convert string to int
    By Zavier in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 06:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,492,989.66146 seconds with 17 queries