Enum With Numeric Members

P

Paul

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.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Paul said:
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

Guest

Göran,

How about:

Public Enum NumberOfDecimalPlaces
Auto
One
Two
Three
Four
Five
End Enum

Kerry Moorman
 
P

Paul

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!
 
R

rowe_newsgroups

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
 
P

Paul

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top