473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("yu k!")] LightGreen = 0x012020,
[Description("ni ce :-)")] 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());
DescriptionAttr ibute[] attributes =
(DescriptionAtt ribute[])fi.GetCustomAt tributes(
typeof(Descript ionAttribute), false);
return (attributes.Len gth>0)?attribut es[0].Description:va lue.ToString();
}
Nov 20 '05 #1
3 2936

"Tariq Ahmad" <ta*********@ho tmail.com> wrote in message
news:us******** ********@TK2MSF TNGP10.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("yu k!")] LightGreen = 0x012020,
[Description("ni ce :-)")] 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("y uk!")> LightGreen = &h012020 ''' I may be wrong in the
hex
....
End Enum
public static string GetDescription( Enum value)
{
FieldInfo fi= value.GetType() .GetField(value .ToString());
DescriptionAttr ibute[] attributes =
(DescriptionAtt ribute[])fi.GetCustomAt tributes(
typeof(Descript ionAttribute), false);
return (attributes.Len gth>0)?attribut es[0].Description:va lue.ToString(); }
public shared function GetDescription (value as Enum)
dim fi as fieldinfo
Dim attributes() as descriptionattr ibute

fi = value.gettype() .getfield(value .toString())
attributes = fi.getcustomatt ributes(gettype (descriptionatt ribute),
false)

return iif(attributes. length > 0, attributes(0).d escription,
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).D escription,
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****@blowgoa ts.com> wrote in message
news:eR******** ******@TK2MSFTN GP10.phx.gbl...
:
: "Tariq Ahmad" <ta*********@ho tmail.com> wrote in message
: news:us******** ********@TK2MSF TNGP10.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("yu k!")] LightGreen = 0x012020,
: > [Description("ni ce :-)")] 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("y uk!")> LightGreen = &h012020 ''' I may be wrong in the
: hex
: ....
: End Enum
:
:
:
: > public static string GetDescription( Enum value)
: > {
: > FieldInfo fi= value.GetType() .GetField(value .ToString());
: > DescriptionAttr ibute[] attributes =
: > (DescriptionAtt ribute[])fi.GetCustomAt tributes(
: > typeof(Descript ionAttribute), false);
: > return
: (attributes.Len gth>0)?attribut es[0].Description:va lue.ToString();
: > }
: >
: public shared function GetDescription (value as Enum)
: dim fi as fieldinfo
: Dim attributes() as descriptionattr ibute
:
: fi = value.gettype() .getfield(value .toString())
: attributes = fi.getcustomatt ributes(gettype (descriptionatt ribute),
: false)
:
: return iif(attributes. length > 0, attributes(0).d escription,
: 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**********@n tlworld.com> wrote in message
news:%2******** ********@tk2msf tngp13.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).D escription,
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****@blowgoa ts.com> wrote in message
news:eR******** ******@TK2MSFTN GP10.phx.gbl...
:
: "Tariq Ahmad" <ta*********@ho tmail.com> wrote in message
: news:us******** ********@TK2MSF TNGP10.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("yu k!")] LightGreen = 0x012020,
: > [Description("ni ce :-)")] 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("y uk!")> LightGreen = &h012020 ''' I may be wrong in the : hex
: ....
: End Enum
:
:
:
: > public static string GetDescription( Enum value)
: > {
: > FieldInfo fi= value.GetType() .GetField(value .ToString());
: > DescriptionAttr ibute[] attributes =
: > (DescriptionAtt ribute[])fi.GetCustomAt tributes(
: > typeof(Descript ionAttribute), false);
: > return
: (attributes.Len gth>0)?attribut es[0].Description:va lue.ToString();
: > }
: >
: public shared function GetDescription (value as Enum)
: dim fi as fieldinfo
: Dim attributes() as descriptionattr ibute
:
: fi = value.gettype() .getfield(value .toString())
: attributes = fi.getcustomatt ributes(gettype (descriptionatt ribute),
: false)
:
: return iif(attributes. length > 0, attributes(0).d escription,
: 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
29064
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 Case" (with spaces). Thanx! -- Greg Collins Please visit: http://www.InfoPathDev.com
5
8649
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 to the VB6 controls. In VB.NET, you can't set colors that way anymore, now you have to use a "color". There is a way to convert RGB values to a "color", using the Color.FromARGB method. But there doens't seem to be a way to convert the old...
5
3907
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 = fileSize; byte b = new byte;
6
5277
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 Convert.FromBase64String seem like the closest thing I can find to what I'm looking for baked into the base class library. Can anyone suggest a better way to do this? TIA - Bob
0
1864
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 path of any file that user wants. After that i need to show the preview of that file. If there is any way to convert any document in xps file then i can convert it in tiff file format. So please if you have any idea to convert document in xps format...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.