473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

can u convert this to vb.net please?

got this code from codeproject.com, but cant convert it to vb.

can u help please? thnx.

t.

----------------------------------------------------------------------------
-------

Append a Description attribute to each enum entry:

private enum MyColors
{
[Description("yuk!")] LightGreen = 0x012020,
[Description("nice :-)")] VeryDeepPink = 0x123456,
[Description("so what")] InvisibleGray = 0x456730,
[Description("no comment")] DeepestRed = 0xfafafa,
[Description("I give up")] PitchBlack = 0xffffff,
}To access the description from code, the following function is called:

public static string GetDescription(Enum value)
{
FieldInfo fi= value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);
return (attributes.Length>0)?attributes[0].Description:value.ToString();
}
Nov 20 '05 #1
3 2916

"Tariq Ahmad" <ta*********@hotmail.com> wrote in message
news:us****************@TK2MSFTNGP10.phx.gbl...
got this code from codeproject.com, but cant convert it to vb.

can u help please? thnx.

t.

-------------------------------------------------------------------------- -- -------

Append a Description attribute to each enum entry:

private enum MyColors
{
[Description("yuk!")] LightGreen = 0x012020,
[Description("nice :-)")] VeryDeepPink = 0x123456,
[Description("so what")] InvisibleGray = 0x456730,
[Description("no comment")] DeepestRed = 0xfafafa,
[Description("I give up")] PitchBlack = 0xffffff,
}To access the description from code, the following function is called:
Private Enum MyColors
<Description("yuk!")> LightGreen = &h012020 ''' I may be wrong in the
hex
....
End Enum
public static string GetDescription(Enum value)
{
FieldInfo fi= value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);
return (attributes.Length>0)?attributes[0].Description:value.ToString(); }
public shared function GetDescription (value as Enum)
dim fi as fieldinfo
Dim attributes() as descriptionattribute

fi = value.gettype().getfield(value.toString())
attributes = fi.getcustomattributes(gettype(descriptionattribut e),
false)

return iif(attributes.length > 0, attributes(0).description,
value.tostring()
''' this part may be wrong, I'm just doing it on the fly but this should
get you going
End sub

Nov 20 '05 #2
You should enable option strict in Outlook ;-)

: public shared function GetDescription (value as Enum)

Public Shared Function GetDescription(ByVal value As Enum) As String
..
..
..

Return IIf(attributes.Length > 0, attributes(0).Description,
value.ToString).ToString

End Function

: End sub

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
:
: "Tariq Ahmad" <ta*********@hotmail.com> wrote in message
: news:us****************@TK2MSFTNGP10.phx.gbl...
: > got this code from codeproject.com, but cant convert it to vb.
: >
: > can u help please? thnx.
: >
: > t.
: >
:
--------------------------------------------------------------------------

: --
: > -------
: >
: > Append a Description attribute to each enum entry:
: >
: > private enum MyColors
: > {
: > [Description("yuk!")] LightGreen = 0x012020,
: > [Description("nice :-)")] VeryDeepPink = 0x123456,
: > [Description("so what")] InvisibleGray = 0x456730,
: > [Description("no comment")] DeepestRed = 0xfafafa,
: > [Description("I give up")] PitchBlack = 0xffffff,
: > }To access the description from code, the following function is called:
: >
: Private Enum MyColors
: <Description("yuk!")> LightGreen = &h012020 ''' I may be wrong in the
: hex
: ....
: End Enum
:
:
:
: > public static string GetDescription(Enum value)
: > {
: > FieldInfo fi= value.GetType().GetField(value.ToString());
: > DescriptionAttribute[] attributes =
: > (DescriptionAttribute[])fi.GetCustomAttributes(
: > typeof(DescriptionAttribute), false);
: > return
: (attributes.Length>0)?attributes[0].Description:value.ToString();
: > }
: >
: public shared function GetDescription (value as Enum)
: dim fi as fieldinfo
: Dim attributes() as descriptionattribute
:
: fi = value.gettype().getfield(value.toString())
: attributes = fi.getcustomattributes(gettype(descriptionattribut e),
: false)
:
: return iif(attributes.length > 0, attributes(0).description,
: value.tostring()
: ''' this part may be wrong, I'm just doing it on the fly but this should
: get you going
: End sub
:
: >
:
:
Nov 20 '05 #3
Is that under Tools -> Options -> Intellisesne -> Newsgroups?

=)

my bad. Thanks for fixing that though Tom.
"Tom Spink" <th**********@ntlworld.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
You should enable option strict in Outlook ;-)

: public shared function GetDescription (value as Enum)

Public Shared Function GetDescription(ByVal value As Enum) As String
.
.
.

Return IIf(attributes.Length > 0, attributes(0).Description,
value.ToString).ToString

End Function

: End sub

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
:
: "Tariq Ahmad" <ta*********@hotmail.com> wrote in message
: news:us****************@TK2MSFTNGP10.phx.gbl...
: > got this code from codeproject.com, but cant convert it to vb.
: >
: > can u help please? thnx.
: >
: > t.
: >
:

--------------------------------------------------------------------------
: --
: > -------
: >
: > Append a Description attribute to each enum entry:
: >
: > private enum MyColors
: > {
: > [Description("yuk!")] LightGreen = 0x012020,
: > [Description("nice :-)")] VeryDeepPink = 0x123456,
: > [Description("so what")] InvisibleGray = 0x456730,
: > [Description("no comment")] DeepestRed = 0xfafafa,
: > [Description("I give up")] PitchBlack = 0xffffff,
: > }To access the description from code, the following function is called: : >
: Private Enum MyColors
: <Description("yuk!")> LightGreen = &h012020 ''' I may be wrong in the : hex
: ....
: End Enum
:
:
:
: > public static string GetDescription(Enum value)
: > {
: > FieldInfo fi= value.GetType().GetField(value.ToString());
: > DescriptionAttribute[] attributes =
: > (DescriptionAttribute[])fi.GetCustomAttributes(
: > typeof(DescriptionAttribute), false);
: > return
: (attributes.Length>0)?attributes[0].Description:value.ToString();
: > }
: >
: public shared function GetDescription (value as Enum)
: dim fi as fieldinfo
: Dim attributes() as descriptionattribute
:
: fi = value.gettype().getfield(value.toString())
: attributes = fi.getcustomattributes(gettype(descriptionattribut e),
: false)
:
: return iif(attributes.length > 0, attributes(0).description,
: value.tostring()
: ''' this part may be wrong, I'm just doing it on the fly but this should : get you going
: End sub
:
: >
:
:

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Greg Collins [InfoPath MVP] | last post by:
I couldn't find anything in my searches... I'm wondering if there's a Regex (with or without additional C# code) that can convert a either "lowerCamelCase" or "UpperCamelCase" into a proper "Title...
5
by: Bob Homes | last post by:
In VB6, foreground and background colors of controls had to be assigned a single number. If you knew the RGB values for the color, you still had to convert them into the single number accepatable...
5
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer...
6
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and...
0
by: ashz | last post by:
Hi All, I want to convert any document to tiff file format. Is it possible using dot net. Actually i have a simple button in my form that open a OpenFileDialog control. Using this i get the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.