Need help with scope

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I want to create a public enum that can be used throughout a project. I
created an enum like this in a module:

Public Enum ParentType
Project = 0
Stage = 1
VIP = 2
Func = 3
Equipment = 4
Idea = 5
Tech = 6
End Enum

I have been able to declare private variables as ParentType and pass them as
parameters from method to method OK. Now I need to create a public property
in a class as ParentType like this:


Private miCurrentParentType As ParentType

Public Property CurrentParentType() As ParentType
Get
Return miCurrentParentType
End Get
Set(ByVal Value As ParentType)
miCurrentParentType = Value
End Set
End Property

I get a blue squiggly under ParentType in the line:
Public Property CurrentParentType() As ParentType

and the compile error is:
'CurrentParentType' cannot expose a Friend type outside of the Public class
'Tech_UIL'.

I often have similar problems where I have a public enum or structure and
want to declare variables as these types and pass or reference them around
the application.

Is there a way to do this? Also, eventually, the project will be broken
into smaller projects such as a business tier and data access tier and I
will want to have these types referenced as described above throughout the
entire solution across projects.

any recomendations?

Thanks.
 
moondaddy said:
I want to create a public enum that can be used throughout a project. I
created an enum like this in a module:

Public Enum ParentType
Project = 0
Stage = 1
VIP = 2
Func = 3
Equipment = 4
Idea = 5
Tech = 6
End Enum

I have been able to declare private variables as ParentType and pass them
as parameters from method to method OK. Now I need to create a public
property in a class as ParentType like this:


Private miCurrentParentType As ParentType

Public Property CurrentParentType() As ParentType
Get
Return miCurrentParentType
End Get
Set(ByVal Value As ParentType)
miCurrentParentType = Value
End Set
End Property

I get a blue squiggly under ParentType in the line:
Public Property CurrentParentType() As ParentType

and the compile error is:
'CurrentParentType' cannot expose a Friend type outside of the Public
class 'Tech_UIL'.

Place the 'Public Enum...End Enum' /outside/ any module, for example, in a
separate file.
 
There is something wrong in your post, because if the ParentType enum is
declared as Public as you state, it works fine. Only if you change its scope
to Friend you get that error.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
Carlos (& moondaddy),The default for Modules are Friend, which (more then likely) means that
moondaddy has something like:

Module SomeModule

End Module

Which causes the error. As Herfried suggests, do not put Enums in a Module,
simply put them in a source file.

Friend Module SomeModule

End Module

moondaddy,
Structures, Enums & Delegates can all be put in their own source files, they
do not need to be contained directly within Module statements.

Hope this helps
Jay

Carlos J. Quintero said:
There is something wrong in your post, because if the ParentType enum is
declared as Public as you state, it works fine. Only if you change its
scope to Friend you get that error.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
Can't you put the Enums before your Module Statement like:

PUblic Enum myEnum
first
End Enum

PUblic Module myModule
.....
End Module
 
Thanks to all that replied. Using a source file sounds like a good way to
go. I never thought of that before. How do I use a source file? does it
need to have a particular file extension on it? Any instructions would be
great.

Thanks!

--
(e-mail address removed)
Jay B. Harlow said:
Carlos (& moondaddy),The default for Modules are Friend, which (more then likely) means that
moondaddy has something like:

Module SomeModule

End Module

Which causes the error. As Herfried suggests, do not put Enums in a
Module, simply put them in a source file.

Friend Module SomeModule

End Module

moondaddy,
Structures, Enums & Delegates can all be put in their own source files,
they do not need to be contained directly within Module statements.

Hope this helps
Jay
 
Moondaddy,
How do I use a source file?
I normally add a Class or Module to my project then change the Class or
Module definition to Structure or Enum, which ever one I needed.

For example:
1. Add a new Module called "ParentType", giving a .vb file with:

Module ParentType

End Module

2. Change Module to Enum

Public Enum ParentType
...
End Enum

Most of the time I try to limit one type (Class, Module, Structure, Enum) to
a file, however I will include Enums & Delegates in with other types that
they are closely related to.
does it need to have a particular file extension on it?
All source files in VB.NET use the .vb extension.

Hope this helps
Jay
 
Thanks that works total great! Can you refer any documention on other good
ways to use source files?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top