Solved

Compare Enum String

Posted on 2009-04-10
6
298 Views
Last Modified: 2012-05-06
Hi,

I want to compare enum using string value.

i.e

Dim strAlpabet as string ="A"

Select  strAlpabet

      Case .... (A)
            msgbox "Order Number is 1"          

      Case .... (B)
            msgbox "Order Number is 2"          
End Select

How could I do it?

Thank you.
Public Enum Alphabet
 

        A = 1

        B = 2

        C = 3
 

    End Enum

Open in new window

0
Comment
Question by:emi_sastra
  • 3
  • 3
6 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24121057
You don't need a Select Case statement in this case. Simply parse the string...

    Dim OrderNumber As Integer = Convert.ToInt32([Enum].Parse(GetType(Alphabet), "A"))

Wayne
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24121068
Hi webtubbs,

I need using select case.
Please see below code.

Thank you.
Select Case strTrsId

                Case mdlGlobalInv.FakturPenjualanTrsId.NilaiBrg, _

                     mdlGlobalInv.FakturPenjualanTrsId.BiayaAngkut, _

                     mdlGlobalInv.FakturPenjualanTrsId.NilaiDisc, _

                     mdlGlobalInv.FakturPenjualanTrsId.NilaiUangMuka

                    strFieldName = [Enum].GetName(GetType(mdlGlobalInv.FakturPenjualanTrsId), intEnumNumber) & strFieldNilaiKurs

                    strFieldNameToCheck = strFieldName
 

                Case mdlGlobalInv.FakturPenjualanTrsId.NilaiPPNRp, _

                     mdlGlobalInv.FakturPenjualanTrsId.NilaiPPhRp, _

                     mdlGlobalInv.FakturPenjualanTrsId.NilaiMaterai

                    strFieldName = [Enum].GetName(GetType(mdlGlobalInv.FakturPenjualanTrsId), intEnumNumber)

                    strFieldNameToCheck = strFieldName

 

            End Select

Open in new window

0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24121082
OK, try something like this....
        Dim strAlpabet As String = "C"

        Select Case CType([Enum].Parse(GetType(Alphabet), strAlpabet), Alphabet)

            Case Alphabet.A

                MsgBox(1)

            Case Alphabet.B

                MsgBox(2)

            Case Alphabet.C

                MsgBox(3)

        End Select

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:emi_sastra
ID: 24121090
Select Case CType([Enum].Parse(GetType(Alphabet), strAlpabet), Alphabet)

What does it mean? Convert to numeric?

Thank you.
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24121096
No, it converts it to the equivalent enumeration value.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24121134
Ok.

Thank you very much for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now