Solved

Compare Enum String

Posted on 2009-04-10
6
297 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

23 Experts available now in Live!

Get 1:1 Help Now