473,698 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enum With Numeric Members

VB.NET - VS 2005

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

Public Enum NumberOfDecimal Places
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 4882
Paul wrote:
VB.NET - VS 2005

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

Public Enum NumberOfDecimal Places
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 NumberOfDecimal Places
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 NumberOfDecimal Places
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
NumberOfDecimal s.2 or NumberofDecimal s.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
4842
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 EnumName FirstValue = 1 SecondValue = 2 ThirdValue = 3
12
3419
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 static const * int class members as opposed to using enumerations to accomplish a * similar goal. The use of static constants seems more explicit and * obvious to me. Unless I assign values to the enumerators, the * compiler will do it for me....
4
3051
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 { DOUBLE_LIST, INT_LIST } DATA_TYPE; typedef struct { DATA_TYPE type;
18
2372
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 there was a bit more typechecking ?
11
1232
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
12381
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
9212
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 - this is 4 for the example given. One not very good way that I currently use is to add a dummy "LENGTH" member on the end: enum ParamTest {Err, Start, Block, Hold, LENGTH}
3
2092
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
1832
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 in evidence. Maybe it's my fault for having reacted with a little annoyance, but anyway I'm tired of waiting days for moderators, have had several posts not get through moderation at all which were certainly not inappropriate, and an email from...
0
8609
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
9030
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
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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
5861
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.