473,320 Members | 2,145 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.

Help with a simple enum error

Hi all,

I thought that if I declared an Enum as follows:

public enum RolesEnumeration{
GlobalAdmin = 0,
PrincipalTrialInvestigator = 1,
TrialManager = 2,
AssistantTrialManager = 3,
GroupCoordinator = 4,
GroupTrialManager = 5,
GroupDataManager = 6,
ClinicalResearchAssistant = 7,
StudyManagementCommittee = 8,
PrincipalSiteInvestigator = 9,
SiteCoInvestigator = 10,
SiteStudyNurses = 11,
Patient = 12,
IndustryUser = 13,
Others = 14,
LabResearcher = 15,
DataAndEthicsMonitoringCommittee = 16
}

Then I could make a statement like:
if(roleID <= RolesEnumeration.GolbalAdmin){
....

At the moment though, the compiler is telling me that:
Operator '<=' cannot be applied to operands of type 'int' and
'spirit.secure.RolesEnumeration'

Can anyone see what I've done wrong? I know its going to be something
totally obvious but I cant see it!

Thanks all

Simon
Nov 15 '05 #1
5 1907
Assuming your RoleID is an int, you should do the following:
if(roleID <=(int) RolesEnumeration.GolbalAdmin){

José
"Simon Harvey" <si**********@the-web-works.co.uk> wrote in message
news:OX**************@tk2msftngp13.phx.gbl...
Hi all,

I thought that if I declared an Enum as follows:

public enum RolesEnumeration{
GlobalAdmin = 0,
PrincipalTrialInvestigator = 1,
TrialManager = 2,
AssistantTrialManager = 3,
GroupCoordinator = 4,
GroupTrialManager = 5,
GroupDataManager = 6,
ClinicalResearchAssistant = 7,
StudyManagementCommittee = 8,
PrincipalSiteInvestigator = 9,
SiteCoInvestigator = 10,
SiteStudyNurses = 11,
Patient = 12,
IndustryUser = 13,
Others = 14,
LabResearcher = 15,
DataAndEthicsMonitoringCommittee = 16
}

Then I could make a statement like:
if(roleID <= RolesEnumeration.GolbalAdmin){
...

At the moment though, the compiler is telling me that:
Operator '<=' cannot be applied to operands of type 'int' and
'spirit.secure.RolesEnumeration'

Can anyone see what I've done wrong? I know its going to be something
totally obvious but I cant see it!

Thanks all

Simon

Nov 15 '05 #2
Hi Simon,
Can anyone see what I've done wrong? I know its going to be something
totally obvious but I cant see it!
You should cast the enumeration item to int:

if(roleID <= (int)RolesEnumeration.GolbalAdmin)

given roleID is an "int" variable.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Simon Harvey" <si**********@the-web-works.co.uk> wrote in message
news:OX**************@tk2msftngp13.phx.gbl... Hi all,

I thought that if I declared an Enum as follows:

public enum RolesEnumeration{
GlobalAdmin = 0,
PrincipalTrialInvestigator = 1,
TrialManager = 2,
AssistantTrialManager = 3,
GroupCoordinator = 4,
GroupTrialManager = 5,
GroupDataManager = 6,
ClinicalResearchAssistant = 7,
StudyManagementCommittee = 8,
PrincipalSiteInvestigator = 9,
SiteCoInvestigator = 10,
SiteStudyNurses = 11,
Patient = 12,
IndustryUser = 13,
Others = 14,
LabResearcher = 15,
DataAndEthicsMonitoringCommittee = 16
}

Then I could make a statement like:
if(roleID <= RolesEnumeration.GolbalAdmin){
...

At the moment though, the compiler is telling me that:
Operator '<=' cannot be applied to operands of type 'int' and
'spirit.secure.RolesEnumeration'

Can anyone see what I've done wrong? I know its going to be something
totally obvious but I cant see it!

Thanks all

Simon


Nov 15 '05 #3
Simon Harvey <si**********@the-web-works.co.uk> wrote:
I thought that if I declared an Enum as follows:

public enum RolesEnumeration{
GlobalAdmin = 0,
PrincipalTrialInvestigator = 1,
TrialManager = 2,
AssistantTrialManager = 3,
GroupCoordinator = 4,
GroupTrialManager = 5,
GroupDataManager = 6,
ClinicalResearchAssistant = 7,
StudyManagementCommittee = 8,
PrincipalSiteInvestigator = 9,
SiteCoInvestigator = 10,
SiteStudyNurses = 11,
Patient = 12,
IndustryUser = 13,
Others = 14,
LabResearcher = 15,
DataAndEthicsMonitoringCommittee = 16
}

Then I could make a statement like:
if(roleID <= RolesEnumeration.GolbalAdmin){
...

At the moment though, the compiler is telling me that:
Operator '<=' cannot be applied to operands of type 'int' and
'spirit.secure.RolesEnumeration'

Can anyone see what I've done wrong? I know its going to be something
totally obvious but I cant see it!


Well, you haven't shown how you've declared roleID, but I'm assuming
it's as an int rather than a spirit.secure.RolesEnumeration. Cast
either side to the same type as the other and it should be fine, ie:

if ((RolesEnumeration)roleID <= RolesEnumeration.GlobalAdmin)

or

if (roleID <= (int)RolesEnumeration.GlobalAdmin)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Thanks everyone!

I knew it would be something simple like that. I thought the compiler would
know it was an int I was dealing with.

I'll remember that for the future.

Thanks again everyone

Kindest Regards

Simon
Nov 15 '05 #5
Simon Harvey <si**********@the-web-works.co.uk> wrote:
Thanks everyone!

I knew it would be something simple like that. I thought the compiler would
know it was an int I was dealing with.


Fortunately not. If it did, you'd just have got rid of a lot of type-
safety, and you might as well just use integer constants :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

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

Similar topics

1
by: Durairaj Avasi | last post by:
#!/usr/bin/perl -w use Net::LDAP; use Net::LDAP::Util qw(ldap_error_name ldap_error_text); my $ldap = Net::LDAP->new('xy.webdurai.net', port=> 389) or die "$@"; $ldap->debug(15); my @args = (...
4
by: Revman | last post by:
I'm having problems opening and reading from a file to test a Class. My diver main.cpp is fairly short but with a longer file open function // Project #4 -- Main/driver program #include...
13
by: Chua Wen Ching | last post by:
Hi there, I saw this article here in vb.net. http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx and ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
8
by: Martin Horn | last post by:
Hi, I am trying to add extra functionality to the standard RichText control, but I've fallen at the first hurdle,can someone take a look at the following code and tell me why it fails to return...
7
by: moondaddy | last post by:
I want to create a public enum that can be used throughout a project. I created an enum like this in a module: Public Enum ParentType Project = 0 Stage = 1 VIP = 2 Func = 3 Equipment = 4...
10
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got errors just trying to compile the header enum.h. ...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
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.