Enumeration error in interface module

Hi guys,
I've declared a Public enumeration (called MyRole) in a standard module and I can use it without any problems in all my class modules except in an interface module.

I get the following error message "'MyRole' cannot expose type 'GlobalDeclarations.MyRole' outside the project through interface 'MyInterface'". I can get around it by using String or Integer for example but I'd really like to use the enumeration, for obvious reasons.

Is there any way around it?

/Michael

'---GlobalDeclarations module
    Public Enum MyRole As Short
        Tender = 0
        Variation = 1
    End Enum

'---Class X module
Friend ReadOnly Property Role() As String Implements VarIF.MyRole
.......
End Property

'---VarIF interface module (that gives an error)
ReadOnly Property Role() As MyRole
gem56Asked:
Who is Participating?
 
doraiswamyConnect With a Mentor Commented:
Why not declare the enum in the interface?
e.g.
Public Interface Interface1

    Enum MyRole As Short
        Tender = 0
        Variation = 1
    End Enum

    ReadOnly Property Role()

End Interface

Public Class Class1
    Implements Interface1
    Dim r As Interface1.MyRole = Interface1.MyRole.Tender

    Public ReadOnly Property Role() As Object Implements Interface1.Role
        Get
            Return r
        End Get
    End Property
End Class
0
 
gem56Author Commented:
Thanks for that doraiswamy. That's done the trick.

Just for future reference, is there no way of using an externally defined enumerations in an interface.
I ask that because it worked out OK this time but in future it may not be possible to relocate the declaration to the interface.

/Michael
0
 
doraiswamyCommented:
To my current knowledge, no.
This is probably because the interface does not want any external dependencies. If what you were initially trying was allowed, then you would have to somehow bind your global module along with the interface. However by not specifying the return type of Role in the interface, I accomplished what you may want:

Public Interface Interface1
    ReadOnly Property Role()
End Interface

Module Module1
    Public Enum MyRole As Short
        Tender = 0
        Variation = 1
    End Enum
End Module

Public Class Class1
    Implements Interface1
    Dim r As Module1.MyRole = MyRole.Tender

    Public ReadOnly Property Role() Implements Interface1.Role
        Get
            Return r
        End Get
    End Property

End Class
0
 
gem56Author Commented:
Thanks a lot for your earlier solution doraiswamy and your explanation.
/Micael

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.