#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Enum Names

how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Enum Names

I don't believe that you can. Enum is used to declare a type for
enumeration, so you can declare a data type of that enumeration, or you can
use any of the member names within your code, but you can't go the other
way. You may have many such types, all with a member value of 2, so which
would it return.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Goofy" wrote in message
...
how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Enum Names

Well, the enum groupname would be the way of resolving this. In
microsoft.NET you can reveal the name of the enum from the value within it.


"Bob Phillips" wrote in message
...
I don't believe that you can. Enum is used to declare a type for
enumeration, so you can declare a data type of that enumeration, or you
can
use any of the member names within your code, but you can't go the other
way. You may have many such types, all with a member value of 2, so which
would it return.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Goofy" wrote in message
...
how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Enum Names

Hi,

Check Chip Pearson's site.
http://www.cpearson.com/excel/download.htm

In particular the TLIUtils example.
"Provides VBA procedures for working with type libraries, via the
TypeLib Information object. Documentation of the available procedures is
available in the VBA code modules."

Cheers
Andy

Goofy wrote:
how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Enum Names

Thanks

"Andy Pope" wrote in message
...
Hi,

Check Chip Pearson's site.
http://www.cpearson.com/excel/download.htm

In particular the TLIUtils example.
"Provides VBA procedures for working with type libraries, via the TypeLib
Information object. Documentation of the available procedures is available
in the VBA code modules."

Cheers
Andy

Goofy wrote:
how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Enum Names

As Bob says, these do not really exist in compiled code, as they have been
replaced with their values, the same as a Const is.
Not sure if this is strictly a correct example, but..
You can use them when you set a value :
ActiveCell.Borders(xlEdgeBottom).LineStyle = xlDashDot
but when retrieving the value :
?ActiveCell.Borders(xlEdgeBottom).LineStyle
4

not xlDashDot

Using Chip's method, you are querying the Type Library for the enum's value,
not the compiled code.

You can link the enum values to an arry of string though

Dim MyEnumString(1 to 2) as string

MyEnumString(firstKey)="firstKey"
MyEnumString(secondKey)="secondKey"

as long as you enum is compiled before your array elements are assigned.
Depends why you need to do this, as the actual name of the enum element does
not have any real meaning as it's only to aid your memory. It's the numeric
value that matters.

NickHK

"Goofy" wrote in message
...
how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Enum Names

Thanks


"NickHK" wrote in message
...
As Bob says, these do not really exist in compiled code, as they have been
replaced with their values, the same as a Const is.
Not sure if this is strictly a correct example, but..
You can use them when you set a value :
ActiveCell.Borders(xlEdgeBottom).LineStyle = xlDashDot
but when retrieving the value :
?ActiveCell.Borders(xlEdgeBottom).LineStyle
4

not xlDashDot

Using Chip's method, you are querying the Type Library for the enum's
value,
not the compiled code.

You can link the enum values to an arry of string though

Dim MyEnumString(1 to 2) as string

MyEnumString(firstKey)="firstKey"
MyEnumString(secondKey)="secondKey"

as long as you enum is compiled before your array elements are assigned.
Depends why you need to do this, as the actual name of the enum element
does
not have any real meaning as it's only to aid your memory. It's the
numeric
value that matters.

NickHK

"Goofy" wrote in message
...
how can I retreive the string value of the enum internal identifier, in
other words if I have a value of 2 I want the corresponding "secondKey"


Public Enum MyEnum

firstKey = 1
secondKey = 2

End Enum






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 97 Enum Larry Dodd[_2_] Excel Programming 5 April 11th 05 11:15 AM
Enum Daniel[_4_] Excel Programming 3 December 22nd 03 12:30 AM
Enum in Excel 97 Rob Bovey Excel Programming 0 September 26th 03 11:02 PM
Enum in Excel 97 Chip Pearson Excel Programming 0 September 26th 03 10:03 PM


All times are GMT +1. The time now is 10:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"