Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-07-2009
Member
 
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.
Reply With Quote
  #2  
Old 30-07-2009
Member
 
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);
Reply With Quote
  #3  
Old 30-07-2009
Member
 
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
Reply With Quote
  #4  
Old 30-07-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to convert string to enum in vb.net application"
Thread Thread Starter Forum Replies Last Post
Convert string into int in C screwball Software Development 4 22-12-2011 08:47 PM
Convert XML string into DOM GreatThinker Software Development 6 22-07-2010 09:48 AM
Convert String to filename Maya Angelou Software Development 5 12-03-2010 01:20 PM
How to convert string to float c# Pratyush Software Development 3 14-08-2009 01:09 PM
How to convert string to int Zavier Software Development 3 04-06-2009 06:24 PM


All times are GMT +5.5. The time now is 11:09 AM.