|
-
Jul 6th, 2004, 06:52 AM
#1
Thread Starter
New Member
Enumeration Issue...
I've come across the following issue with enumerations:
Code:
Public Enum Figures
test1 = 1
test2 = 2
End Enum
Dim fig As Figures
'this works fine (as it should)
fig = Figures.test1
'but this also works even though its not a valid enumeration value!
fig = 4
Can anyone explain why this is allowed to happen and if there is a way to prevent it?
Thanks
-
Jul 6th, 2004, 07:28 PM
#2
Fanatic Member
Yup. You should define fig as a property and in the set you can make sure the integer that is being passed in is in the enumeration by:
Code:
If [Enum].IsDefined(....) Then ....
-
Jul 6th, 2004, 07:40 PM
#3
Sleep mode
Aren't enums are constant values so you can't change them !!! You probably should be looking at Structures not Enums .
-
Jul 7th, 2004, 02:46 AM
#4
Thread Starter
New Member
Thanks for the suggestions guys, it looks like I'm gonna have to use a property instead. It still seems very backward though, as my idea of an enumeration is to ensure a finite list of strongly-typed values, but whats the point if you can still get away with putting any old rubbish in?
-
Jul 7th, 2004, 04:09 AM
#5
Hi.
If you turn Option Strict on it will complain.
Sometimes you need to be able to have a value different from the options specified. If could be a flagged value.
A=Figures.Test1 or Figures.Test2
In your case, that would result in A=3, which is not in the list by itself, but by a combination of Test1 and Test2.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|