enums

  • Thread starter Thread starter martin
  • Start date Start date
M

martin

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