PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET Get Const. Name

Reply

Get Const. Name

 
Thread Tools Rate Thread
Old 13-01-2006, 05:01 PM   #1
=?Utf-8?B?QW1qYWQ=?=
Guest
 
Posts: n/a
Default Get Const. Name


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?


  Reply With Quote
Old 13-01-2006, 05:18 PM   #2
Peter Macej
Guest
 
Posts: n/a
Default Re: Get Const. Name

> 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/micr...48a6ddb220e5aff
http://groups.google.com/group/micr...dc41ad1d52c4d04
for more info.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
  Reply With Quote
Old 13-01-2006, 07:53 PM   #3
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: Get Const. Name

"Amjad" <Amjad@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/>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off