473,513 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enums

Hi,

Is it possible to declare an enum and then declare a variable of the enum
type.
Public Class SessionVars
Inherits Object
Public Shared strGroupName As String
Public Shared strPracticeName As String
Public Shared mode As Modes
<------------------------------*******ERROR*******

Public Sub New()
MyBase.new()
End Sub

Protected Enum Modes As Integer
ModeAdd = 1
ModeEdit = 2
ModeView = 3
End Enum
End Class

I would like to be able to write in code

SessionVars.mode = Modes ModeAdd --and have intellisense pop the modes
up for me.

can anybody help me out or point me in the correct direction???

any help is appreciated.

cheers

martin.
Nov 18 '05 #1
2 946
Not sure how Shared variables change things, but this works:

Public Class Foo
Private mModes As Modes

Public Property MyMode() As Modes
Get
Return mModes
End Get
Set(ByVal Value As Modes)
mModes = Value
End Set
End Property

Public Sub Some Method
If MyMode= Modes.Add Then
etc.
End Sub

'remove extra Mode from "ModeAdd", etc.
Protected Enum Modes As Integer
Add = 1
Edit = 2
View = 3
End Enum

End Class

--
Joe Fallon


"martin" <St**************@yahoo.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Hi,

Is it possible to declare an enum and then declare a variable of the enum
type.
Public Class SessionVars
Inherits Object
Public Shared strGroupName As String
Public Shared strPracticeName As String
Public Shared mode As Modes
<------------------------------*******ERROR*******

Public Sub New()
MyBase.new()
End Sub

Protected Enum Modes As Integer
ModeAdd = 1
ModeEdit = 2
ModeView = 3
End Enum
End Class

I would like to be able to write in code

SessionVars.mode = Modes ModeAdd --and have intellisense pop the modes up for me.

can anybody help me out or point me in the correct direction???

any help is appreciated.

cheers

martin.

Nov 18 '05 #2
Of course it's an error! Seems like common sense to me.

If your enum is a protected within SessionVars and you declare a public
variable of type Modes, how is the outside world supposed to know what Modes
is?
"martin" <St**************@yahoo.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Hi,

Is it possible to declare an enum and then declare a variable of the enum
type.
Public Class SessionVars
Inherits Object
Public Shared strGroupName As String
Public Shared strPracticeName As String
Public Shared mode As Modes
<------------------------------*******ERROR*******

Public Sub New()
MyBase.new()
End Sub

Protected Enum Modes As Integer
ModeAdd = 1
ModeEdit = 2
ModeView = 3
End Enum
End Class

I would like to be able to write in code

SessionVars.mode = Modes ModeAdd --and have intellisense pop the modes up for me.

can anybody help me out or point me in the correct direction???

any help is appreciated.

cheers

martin.

Nov 18 '05 #3

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

Similar topics

13
9513
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
2
2054
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
27
2704
by: Mark A. Gibbs | last post by:
i have been toying with the idea of making my enums smarter - ie, more in line with the rest of the language. i haven't tested it yet, but what i came up with is a template like this: template...
2
1779
by: SpotNet | last post by:
Hello CSharpies, Can Enums in C# be UInt32 Types, and not just Int32 Types. I have a lot of constant declarations that are UInt32 that I want to put in Enums to ease the use of Intellisence. I...
4
5564
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and...
2
1979
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
2
2873
by: Simon Elliott | last post by:
I have some legacy C++ code which requires some enums to be 1 or 2 bytes in size. I'd ideally like to be able to specify that a few carefully selected enums are a particular size. By default,...
11
12422
by: Marc Gravell | last post by:
This one stumped me while refactoring some code to use generics... Suppose I declare an enum MyEnum {...} Is there a good reason why MyEnum doesn't implement IEquatable<MyEnum> ? Of course,...
4
2988
by: Jon Slaughter | last post by:
is there a simple way to "step" through enums? I have a button that I want to click and have it "cycle" through a set of states defined by enums but the only way I can think of doing this...
13
4975
by: Bob | last post by:
Hi, Can someone explain why you can't declare enums in an interface? The compiler says "interfaces can't declare types" Ignoring the syntax implications it seems to me that you should be able to...
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
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...
0
7391
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,...
1
7120
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...
0
5697
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,...
1
5100
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...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
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 ...
1
809
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.