Solved

Compare Enum String

Posted on 2009-04-10
6
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

627 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