Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Compare Enum String

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
emi_sastra
Asked:
emi_sastra
  • 3
  • 3
1 Solution
 
Wayne Taylor (webtubbs)Commented:
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
 
emi_sastraAuthor Commented:
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
 
Wayne Taylor (webtubbs)Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

What does it mean? Convert to numeric?

Thank you.
0
 
Wayne Taylor (webtubbs)Commented:
No, it converts it to the equivalent enumeration value.
0
 
emi_sastraAuthor Commented:
Ok.

Thank you very much for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now