Structures, Classes, Enums, Oh My!

P

Paul

I have a situation that I want to work but don't know the proper way to
handle it.

I want to create a User Defined "Type" (structure, class or
enumeration). I'm not sure what it should be or where it should
reside. I'll use Enum for this example.

Currently in a Public Module:
----------------------------
Public Enum MyUserDefinedType
A = 1
B = 2
C = 3
End Enum


I have a class with a public method.

Currently in a MyTestClass.vb class:
-----------------------------------

Public Class MyTestClass

Public Sub MyObjectsSub1(ByVal P1 As MyUserDefinedType)
... blah, blah, blah
End Sub

End Class

The syntax error I get in the class for using MyUserDefinedType as the
type for P1 is:

'P1' cannot expose a Friend type outside of the public class
'MyTestClass'.

I want my class to be able to use the MyUserDefinedType, but I want my
other code (forms, other modules, etc.) to also be able to use
MyUserDefinedType. Anyone have any thoughts on this?

Any help would be greatly appreciated.
 
J

Jay B. Harlow [MVP - Outlook]

Paul,
| Currently in a Public Module:
| Public Enum MyUserDefinedType
Ah! There's the Rub!!!

I suspect you defined your module as "Module SomeModule" instead of "Public
Module SomeModule" as the default visibilty on modules is Friend.

As you noted Enums are Types just like Modules & Classes. Seeing as Enums
are Types, I normally define them at file level instead of inside a Module
or Class.

When I'm defining an Enum, I normally add a new Class to my project to give
me the file, then I simply delete the Class definition & add the Enum
definition.

Hope this helps
Jay

|I have a situation that I want to work but don't know the proper way to
| handle it.
|
| I want to create a User Defined "Type" (structure, class or
| enumeration). I'm not sure what it should be or where it should
| reside. I'll use Enum for this example.
|
| Currently in a Public Module:
| ----------------------------
| Public Enum MyUserDefinedType
| A = 1
| B = 2
| C = 3
| End Enum
|
|
| I have a class with a public method.
|
| Currently in a MyTestClass.vb class:
| -----------------------------------
|
| Public Class MyTestClass
|
| Public Sub MyObjectsSub1(ByVal P1 As MyUserDefinedType)
| ... blah, blah, blah
| End Sub
|
| End Class
|
| The syntax error I get in the class for using MyUserDefinedType as the
| type for P1 is:
|
| 'P1' cannot expose a Friend type outside of the public class
| 'MyTestClass'.
|
| I want my class to be able to use the MyUserDefinedType, but I want my
| other code (forms, other modules, etc.) to also be able to use
| MyUserDefinedType. Anyone have any thoughts on this?
|
| Any help would be greatly appreciated.
|
 

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

Top