Home All Groups Group Topic Archive Search About
Author
13 Jan 2006 5:01 PM
Amjad
Hi,

I have a module that contains a large list of Constants (e.g. Const alert1
as Integer = 123), and I have a function that returns an "alert" number as
integer (e.g. 123). Is there a way to present to the user the name of that
constant returned by the function according to the constants list (e.g.
"alert1"), instead of just presenting a numeric value returned (e.g. 123)?

In other words, can I have a reverse mapping of a constant value and its
corresponding constant name?

Author
13 Jan 2006 5:18 PM
Peter Macej
> In other words, can I have a reverse mapping of a constant value and its
> corresponding constant name?

Yes you can. You can get list of all constants using Reflection. Then
you just loop all constants and find the one which has the specified
value. Then you can get its name.

See
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/a73d6b81389ddd4e/248a6ddb220e5aff
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/2b0317041399ef13/edc41ad1d52c4d04
for more info.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Author
13 Jan 2006 7:53 PM
Herfried K. Wagner [MVP]
"Amjad" <Am***@discussions.microsoft.com> schrieb:
> I have a module that contains a large list of Constants (e.g. Const alert1
> as Integer = 123), and I have a function that returns an "alert" number as
> integer (e.g. 123). Is there a way to present to the user the name of that
> constant returned by the function according to the constants list (e.g.
> "alert1"), instead of just presenting a numeric value returned (e.g. 123)?

Use an enumeration type (keyword 'Enum').

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>