Results 1 to 6 of 6

Thread: [RESOLVED] Enumeration Warning ... Access of shared member (Enum in this case)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    108

    Resolved [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?

  2. #2
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    108

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    108

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim mytestenum As TestEnum = TestEnum.x
    2.  
    3. MessageBox.Show(mytestenum.ToString())
    That will display "x" in a message box because that's the value of 'mytestenum'.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    108

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width