Question re structures and scope

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi all,

In a module I have the following structure..

Public Structure ButtonStatusFlags

Public butOK As Boolean
Public butNew As Boolean
Public butView As Boolean

End Structure


And in a usercontrol at class-level I want to declare one of these as
protected..
Protected ButtonStatus As ButtonStatusFlags

this gives me the error 'ButtonStatus cannot expose a Friend type outside of
the public class 'ucMyControl'

However I am able to declare it as FRIEND. This does not make sense to me as
ButtonStatus will be exposed MORE. ie to inheriting classes and outside

Can someone explain why this is so??

I can achieve what I want by moving my structure definition into my
usercontrol class, but I would like to keep it public so that I can use it
elsewhere without having to redefine it in each class.

thanks in advance

Steve
 
Just a suggestion...I would think a usercontrol class that would possibly be
used on different forms in different applications should be encapsulated,
i.e., not rely on external classes. I would move the class to inside the
control class since it's such a simple class. Another solution would be to
create a class library containing the buttonclass and add that to your
usercontrol project. You could then also use the class library in other
projects.
 
Steve,
In a module I have the following structure..
Ah! There's the rub.

Structures do not need to be in a Module, rather then can be in there own
source file. Remember that Modules default to Friend not Public, so when you
have "Module SomeModule" it is really saying "Friend Module SomeModule".

Instead of:

---x--- begin SomeModule.vb ---x---
Module SomeModule
Public Structure ButtonStatusFlags

Public butOK As Boolean
Public butNew As Boolean
Public butView As Boolean

End Structure
End Module
---x--- end SomeModule.vb ---x---

I normally put each structure in their own source file:

---x--- begin ButtonStatusFlags.vb ---x---
Public Structure ButtonStatusFlags

Public butOK As Boolean
Public butNew As Boolean
Public butView As Boolean

End Structure
---x--- end ButtonStatusFlags.vb ---x---

Normally I have a single type (Class, Structure, Enum, Module) in each
source file, I normally put Delegates in the same file as the type they are
closest associated with. Depending on how the Delegate is being used, I will
nest it in another type.

Hope this helps
Jay
 
Jay B. Harlow said:
Steve,
Ah! There's the rub.

Structures do not need to be in a Module, rather then can be in there own
source file. Remember that Modules default to Friend not Public, so when
you have "Module SomeModule" it is really saying "Friend Module
SomeModule".

thanks for clearing that up. I had assumed that as long as the structure
definition was accessible, I should be be able to instantiate one with
whatever scope I wanted. Now I see this is not the case.

I've just established that it works if I just declare the module containing
the structure as public. I think I'll just do that for this project.

thankyou both for your replies
Steve
 

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