Enum

S

shapper

Hello,

I need to set predefined values. So I am using an enum:

' Level
Public Enum Level
Basico1Ciclo
Secundario
Superior
End Enum

The problem is I sometimes I need to display a variable value which has
the type level.
But the value should be:

Basico1Ciclo - "1º Ciclo do Ensino Básico"
Secundario - "Ensino Secundário"
Superior - "Ensino Superior"

How should I do this?

Maybe I am looking at enum the wrong way.

Thanks,
Miguel
 
G

Gabriel Lozano-Morán

You can either:

1. Use a declaritive approach thus use custom attributes and create a
utility class that can read these attributes using reflection
2. You can create a mapper that will map the enum values with the string
values

Gabriel Lozano-Morán

Hello,

I need to set predefined values. So I am using an enum:

' Level
Public Enum Level
Basico1Ciclo
Secundario
Superior
End Enum

The problem is I sometimes I need to display a variable value which has
the type level.
But the value should be:

Basico1Ciclo - "1º Ciclo do Ensino Básico"
Secundario - "Ensino Secundário"
Superior - "Ensino Superior"

How should I do this?

Maybe I am looking at enum the wrong way.

Thanks,
Miguel
 
G

Guest

Hi Miguel,

When working with strings, I've found it easier to just use constants. For
example,

Const Basico1Ciclo As String = "1º Ciclo do Ensino Básico"

I'm mostly familiar with C#, so someone more familiar with VB.NET might
correct my syntax a bit, but this is the general idea.

Joe
 
S

Serge/XX

Hi !

shapper wrote :
I need to set predefined values. So I am using an enum:

' Level
Public Enum Level
Basico1Ciclo
Secundario
Superior
End Enum

The problem is I sometimes I need to display a variable value which has
the type level.
But the value should be:

Basico1Ciclo - "1º Ciclo do Ensino Básico"
Secundario - "Ensino Secundário"
Superior - "Ensino Superior"

How should I do this?

Maybe I am looking at enum the wrong way.

Enum is used for numeric value.
Use instead a static class like this

Public NotInheritable Class Level
Public Const Basico1Ciclo as String = "1º Ciclo do Ensino Básico"
Public Const Secundario as String = "Ensino Secundário"
Public Const Superior as String = "Ensino Superior"
End Class

In your code you can directly access this class like this:

Select case myLevel
Case Level.Basico1Ciclo
'Do somthing
Case Level.Secundario
'Do somthing else
End Select

Or just simply do a
myLabel.text = Level.Secundario

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Enum 4
Enum 1
CheckBox 1
String to Enumeration 1
Enum Extentions 7
Merge Info From Two Enums 1
Data type. Multi pair of values. How can I do this? 2
Enum 3

Top