473,320 Members | 2,122 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,320 software developers and data experts.

Enum With Numeric Members

VB.NET - VS 2005

Is it possible to create an Enum with numeric members. Example:

Public Enum NumberOfDecimalPlaces
Auto
1
2
3
4
5
End Enum

I want this for a property that I have in one of my controls. The
"Auto" member is fine. The numbers generate errors.

May 7 '07 #1
5 4865
Paul wrote:
VB.NET - VS 2005

Is it possible to create an Enum with numeric members. Example:

Public Enum NumberOfDecimalPlaces
Auto
1
2
3
4
5
End Enum

I want this for a property that I have in one of my controls. The
"Auto" member is fine. The numbers generate errors.
The identifiers in an enum has to be identifiers. The name of an
identifier can not be a number.

I suggest that you use a structure instead, having:

:: a constructor that takes a number from 1 to 5
:: a factory property named Auto that creates a zero value
:: an IsAuto property that determines if the value is zero
:: a Value property that returns the value

--
Göran Andersson
_____
http://www.guffa.com
May 8 '07 #2
Göran,

How about:

Public Enum NumberOfDecimalPlaces
Auto
One
Two
Three
Four
Five
End Enum

Kerry Moorman

"Göran Andersson" wrote:
Paul wrote:
VB.NET - VS 2005

Is it possible to create an Enum with numeric members. Example:

Public Enum NumberOfDecimalPlaces
Auto
1
2
3
4
5
End Enum

I want this for a property that I have in one of my controls. The
"Auto" member is fine. The numbers generate errors.

The identifiers in an enum has to be identifiers. The name of an
identifier can not be a number.

I suggest that you use a structure instead, having:

:: a constructor that takes a number from 1 to 5
:: a factory property named Auto that creates a zero value
:: an IsAuto property that determines if the value is zero
:: a Value property that returns the value

--
Göran Andersson
_____
http://www.guffa.com
May 8 '07 #3
Thanks for the replies. Kerry, I thought about your suggestion but I
would prefer the user to be able to enter "2" or "0", actual numbers
into the property.

I also wondered if a Structure would work, but have not taken the time
to investigate it. I'll look into it further.

Thanks again!

May 8 '07 #4
On May 8, 11:11 am, Paul <pwh...@hotmail.comwrote:
Thanks for the replies. Kerry, I thought about your suggestion but I
would prefer the user to be able to enter "2" or "0", actual numbers
into the property.

I also wondered if a Structure would work, but have not taken the time
to investigate it. I'll look into it further.

Thanks again!
Thanks for the replies. Kerry, I thought about your suggestion but I
would prefer the user to be able to enter "2" or "0", actual numbers
into the property.
Remember, they won't be entering in "2" or "0" but rather
NumberOfDecimals.2 or NumberofDecimals.0

Also, who are your users? Are they fellow programmers who are going to
be using your code or just typical user who are using a full fledged
application? If they are just normal users you could just have "Auto,
1, 2, 3, 4, 5" as entries in a combobox and let the user select it
there - there is no reason why the end-user should see the
enumeration.

Thanks,

Seth Rowe

May 8 '07 #5
The "users" are fellow developers. That is why I'm not concerned
about using Auto, 1, 2... I'm just going to go with what I already
used. I made the type be Integer and the Auto value will be -1.

May 9 '07 #6

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

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
12
by: Steven T. Hatton | last post by:
Any opinions or comments on the following? I don't say it below, but I came out on the side of using enumerations over static constants. /* I'm trying to figure out the pros and cons of using...
4
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum {...
18
by: Nebula | last post by:
Consider enum Side {Back,Front,Top,Bottom}; enum Side a; Now, why is a = 124; legal (well it really is an integer, but still, checking could be performed..) ? Wouldn't enums be more useful if...
11
by: Charles Law | last post by:
Hi Guys I'm sure there is a plausible explanation for this, but ... <code> Public Enum Test Abra = 5 Cadabra = 76 End Enum
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
2
by: Jay | last post by:
I have a few enums, a shortened example of one is: enum ParamTest {Err, Start, Block, Hold} Is there a programmatic way to find the number of "members" (probably the wrong C# term) of the Enum...
3
by: Krish | last post by:
I want to have an enum that has a list of numeric values. How do I achieve this? Something like this ... Public Enum AllowedNumbers { 111, 222, 333,
0
by: tony_in_da_uk | last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and got a near-flippant response from someone who clearly didn't take the time to consider the import. I replied, and it's still not...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.