Enum Text Constant

dbarasch

New member
Local time
Yesterday, 22:21
Joined
May 8, 2010
Messages
6
I want to get the text constant from a Enum.

Public Enum DayOfWeek

Monday=1
Tuesday =2
<etc>

End Enum

If I have the number, how do I get the text constant on the enum.

example:

msgbox(1) How would this function return "Monday", not "1"?
 
There's no built-in way to read the text constant. They're just a pointer.

One possible workaround is to build a function that returns the text:

Code:
Public Enum MyEnum
  foo = 1
  bar = 2
  baz = 4
End Enum

Public Function GetMyEnumText(InputValue As MyEnum) As String

Select Case InputValue
   Case foo
      GetMyEnumText = "foo"
   Case bar
      GetMyEnumText = "bar"
   Case baz
      GetMyEnumText = "baz"
   Case Else
      Err.Raise vbObjectError, "GetMyEnumText", "Invalid value given for the input."
End Select

End Function
 

Users who are viewing this thread

Back
Top Bottom