An Enum question


Author
Message
StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Here is the error i'm getting:

'ParentFormID' cannot expose type 'Module1.ParentFormIDEnum' outside the project through class 'MyClass'.

Here is the related code:

Module Module1

    Enum ParentFormIDEnum As Integer
        POReceiving = 1
        Production = 4
        Returns = 5
    End Enum

End Module

Public Class MyClass

    Public WriteOnly Property ParentFormID() As ParentFormIDEnum
        Set(ByVal value As ParentFormIDEnum)
         miParentFormID = value
        End Set
    End Property

End Class

I'm not sure what this error means. All I'm trying to do is create a global enum and be able to use it in all areas of my program.

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Since your enum and module have not been defined as public then you cannot have a public property expose those privately typed classes.  You need to add Public in front of Module and your enum.

I do not recommend using modules!  This was left for backward compatability.  You should use shared classes.  In the case of your enum, just move it outside of the module and it will reside as its own public enum:

Public Enum MyEnum As Integer
   MyValue = 1
End Enum

Paul Chase
Paul Chase
Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Mike,

Your class is public but the module isn't so it is letting you know that your class is public which exposes the module which is friend. Just make the module public and it should work. Or make the class friend

Public module whatever

Paul

StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Thanks Trent. Thanks Paul.

Trent, How is a shared class different from a regular class?

Paul Chase
Paul Chase
Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)Advanced StrataFrame User (576 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Lol didnt see Trent already answered you. I agree about modules.

1)  If you reference your project from another project, whether VB or C#, the module routines aren't accessible even if they're public.

2)  You can name a local method in a class the same as a public module routine, and the compiler won't say anything about it.  When you use the method, the compiler won't require you to prefix it; it'll just happily use the local version instead of the module with no warning.

Shared classes, on the other hand, are accessible to outside projects (if you want them to be), and shared classes avoid the ambiguity because of the prefixed class name.

StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Ok, I moved the enums outside of the Module and now it looks like this:

Public Module Module1

End Module

Public Enum ParentFormIDEnum As Integer
    POReceiving = 1
    Production = 4
    Returns = 5
End Enum

And here's where my VB6 brain Hehe is having trouble... I dont understand how I can place the enum 'outside' of the Module. When I created the module, it created a Module1.vb file... and inside it was

Module Module1

End Module

I assumed that everything had to reside inside there, and the only thing allowed outside was the Imports statements at the top.

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Basically, a "sealed" class is what you use in VB to be a container for methods.  (C# has a "static" class, but "sealed" is as close as you can get in VB).  You create the class, and it becomes the module (actually, when you compile a module in VB.NET, it creates a class out of the module on the back end.. which you can see if you use reflection).

Public NotInheritable Class MyModuleClass

     '-- A private constructor keeps someone from accidentally trying to create an instance of this class
     Private Sub New() 
     End Sub

     '-- All of your methods and fields are then marked with "Shared"
     Public Shared Function MyFunc(ByVal value As String) As String
          '-- Parse the value
     End Function

End Class

'-- When you access these Shared methods and fields, you access them like this:
MyModuleClass.MyFunc("test") '-- you use the ClassName. syntax and you get all of the shared methods on the class

StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Awesome! Thanks for the info.
StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
And here's where my VB6 brain  is having trouble... I dont understand how I can place the enum 'outside' of the Module.

I've seen examples like this:

Public Class Item

End Class

Public Class Inventory

    Dim itm as new Item

End Class

I dont understand how you can have two classes in the same file. I am under the impression that you can only have one class per file.  What gives? Tongue

P.S. I really appreciate this thread and the advice on using a shared class instead of a module... that is invaluable information that I might not otherwise pickup. Cool

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You can have as many classes in a file as you want... you can even have nested classes.  Basically, with VB.NET, you can have a 1 file to 1 class relationship, or you can have a multiple file to 1 class relationship (partial classes... part of the class exists in each file), or you can have a 1 file to multiple class relationship.  The code file does not define a class... the Public Class <ClassName> and End Class do.  Open up one of the .designer.vb files for one of your business objects and drop down the left combo box at the top of the file... you'll see how many classes exist in that one file.  And besides the business object, they're all nested.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search