[RESOLVED] Enumeration Warning ... Access of shared member (Enum in this case)
I created an enumeration in a class library... and compiled it into a dll
Code:
Public Enum TestEnum
x = 0
End Enum
I then imported this reference to a windows form project as a referenced dll
Code:
Public Class Form1
Dim mytestenum As TestPublicEnum.TestEnum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Access of shared member, constant member, enum member or
' nested type through
' an instance; qualifying expression will not be evaluated.
MsgBox(Str(mytestenum.x))
End Sub
End Class
Intellisense will pick up the member (x) in this case but won't evaluate to
mytestenum.x to 0 like i expected.
What am I missing?
Re: Enumeration Warning ... Access of shared member (Enum in this case)
Well works for me... but i had to change mytestenum to TestEnum
Code:
Public Class Form1
Dim mytestenum As TestPublicEnum.TestEnum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Access of shared member, constant member, enum member or
' nested type through
' an instance; qualifying expression will not be evaluated.
MsgBox(Str(TestEnum.x))
End Sub
End Class
Do you have another enum mytestenum.x with a different value?
Kris
Re: Enumeration Warning ... Access of shared member (Enum in this case)
No... i closed other project (library class). This is one of those where i'm going to feel stupid.
Re: Enumeration Warning ... Access of shared member (Enum in this case)
I think the answer is.... how can i expect the member x to have a value... but i thought it would at least default to 0.
Re: Enumeration Warning ... Access of shared member (Enum in this case)
The reason that you get the warning is because you are trying to access a field of an enumeration type via a variable of that type. Your 'mytestenum' doesn't have a member 'x'. The TestEnum type has a member 'x'. You can assign that member to the 'mytestenum' variable and then the value of 'mytestenum' is TestEnum.x.
vb.net Code:
Dim mytestenum As TestEnum = TestEnum.x
MessageBox.Show(mytestenum.ToString())
That will display "x" in a message box because that's the value of 'mytestenum'.
Re: Enumeration Warning ... Access of shared member (Enum in this case)
I had to say it out loud about a dozen times and i believe it will make more sense when i get some sleep.... a lil after 5 a.m. local.
Thx once again partner.