Solved

Enumeration error in interface module

Posted on 2007-11-13
4
742 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:gem56
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
doraiswamy earned 250 total points
Comment Utility
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
 

Author Comment

by:gem56
Comment Utility
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
 
LVL 8

Expert Comment

by:doraiswamy
Comment Utility
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
 

Author Comment

by:gem56
Comment Utility
Thanks a lot for your earlier solution doraiswamy and your explanation.
/Micael

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now