473,811 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum data type

Trying to declare a enum datatype.

Below works

Public Enum EnumCharSet
IBM037
IBM437
IBM500
End Enum

When I add a new string with a "-", error occur says that "End of statement
expected"

For example
Public Enum EnumCharSet
IBM037
IBM437
IBM500
ASMO-708
End Enum

Does not work because ASMO-708 has a "-" there.

What went wrong and what should I do?

regards,

Guoqi Zheng
http://www.ureader.com
Nov 19 '05 #1
4 3171
Notice that each named item in the enumeration is not enclosed in quotes.
Enumerated names are not strings; they're actually constants. If you look
at the IL of an enumeration, you'll see that your Enum is actually a class
that derives from System.Enum. Each name in the Enum becomes a Public Const
field of the class.

Because the names are not strings, the dash is interpreted as a minus sign
which is an illegal character in a type or variable name.

HTH
----------------
Dave Fancher
http://www.davefancher.com

"guoqi zheng" <no@sorry.com > wrote in message
news:77******** *************** *******@ureader .com...
Trying to declare a enum datatype.

Below works

Public Enum EnumCharSet
IBM037
IBM437
IBM500
End Enum

When I add a new string with a "-", error occur says that "End of
statement
expected"

For example
Public Enum EnumCharSet
IBM037
IBM437
IBM500
ASMO-708
End Enum

Does not work because ASMO-708 has a "-" there.

What went wrong and what should I do?

regards,

Guoqi Zheng
http://www.ureader.com

Nov 19 '05 #2
Basically, each enum value must follow the same naming constraints that any
varaible (symbol) would have.

"Dave Fancher" <da**@remove.da vefancher.com> wrote in message
news:Xc******** ************@co mcast.com...
Notice that each named item in the enumeration is not enclosed in quotes.
Enumerated names are not strings; they're actually constants. If you look
at the IL of an enumeration, you'll see that your Enum is actually a class
that derives from System.Enum. Each name in the Enum becomes a Public Const field of the class.

Because the names are not strings, the dash is interpreted as a minus sign
which is an illegal character in a type or variable name.

HTH
----------------
Dave Fancher
http://www.davefancher.com

"guoqi zheng" <no@sorry.com > wrote in message
news:77******** *************** *******@ureader .com...
Trying to declare a enum datatype.

Below works

Public Enum EnumCharSet
IBM037
IBM437
IBM500
End Enum

When I add a new string with a "-", error occur says that "End of
statement
expected"

For example
Public Enum EnumCharSet
IBM037
IBM437
IBM500
ASMO-708
End Enum

Does not work because ASMO-708 has a "-" there.

What went wrong and what should I do?

regards,

Guoqi Zheng
http://www.ureader.com


Nov 19 '05 #3
Thanks for all your replies, problem sloved now. it is better to use a class
in this situation.
Nov 19 '05 #4
Enumerations really boil down to syntactical convenience. Have you
considered using a Hashtable instead?

HTH
----------------
Dave Fancher
http://www.davefancher.com

"guoqi" <no@sorry.com > wrote in message
news:69******** *************** *******@ureader .com...
Thanks for all your replies, problem sloved now. it is better to use a
class
in this situation.

Nov 19 '05 #5

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

Similar topics

20
4856
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
2
3118
by: mrhicks | last post by:
Hello all, I have a question about enumerations. Within some requirements data passed back a certain bit field is defined by three bits then in another section the bit field is defined as 4 bits. The second set is a superset of the first set. The enumeration look as following... enum SET1 { AutoOffState = 0x00, AutoOneState = 0x01, TrippedOffState = 0x02, TrippedOnState = 0x03, LockedOffState = 0x04, LockedOnState = 0x05,
21
4611
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
5
2876
by: Barry | last post by:
Hello, In VS2003, I tried using an enum and setting it into a field in a datarow. It seems as if the datatype of the field in the row determined what went into the field. If the datatype was string, then the name of the enum item went into the field, but if the datatype was integer, then the integer value of the enum was stored. Is this expected behaviour? I couldn't find anything while searching for answers.
34
11210
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
35
15297
by: dtschoepe | last post by:
Greetings. I am working on an assignment and can't seem to get the right concept for something I'm attempting to do with enum data types. I have defined the following in my code: enum color {red, blue, green, yellow, black, purple, pink}; What I am doing now is reading from a text file a string (char *). I
3
3047
by: hufaunder | last post by:
Imagine you have a charting library that can draw lines, bars, floating bars, bands, etc. Lines and bars need only one input. Floating bars and bands need two inputs. There are two approaches: 1) One enum with all 4 types (bars, band, etc). One chart class that accepts up to 2 arrays of values. If the user choses a band but there is only one input array throw an exception. If the user passes two input arrays with different lengths throw...
10
3042
by: Charlie | last post by:
I tried to post this before and I apologize if I am repeating myself, but I do not see the post anywhere. But anyway, I have a file, data.c, where I define all of my global variables. I then use the extern keyword to reference those variables from a header file, data.h, which I include in every file. I am defining an enum type and variable in data.c:
12
22766
by: Charlie | last post by:
I have a file, data.c, where I define all of my global variables. I then have a header file, data.h, which I include in every file in which I reference all of the variables defined in data.c. For the most part, I am having no problem with this. However, I defined an variable of type myenum in data.c: enum myenum {
4
2702
by: jonpb | last post by:
The documentation for the "is" keyword says: An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown. So, given: enum TestEnum { t1, t2 } TestEnum te = TestEnum.t1;
0
9605
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
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10384
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...
0
10130
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
9204
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...
0
5553
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
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
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
3017
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.