473,657 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question re structures and scope

Hi all,

In a module I have the following structure..

Public Structure ButtonStatusFla gs

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 ButtonStatusFla gs

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




Nov 21 '05 #1
5 1188
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" wrote:
Hi all,

In a module I have the following structure..

Public Structure ButtonStatusFla gs

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 ButtonStatusFla gs

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




Nov 21 '05 #2
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" wrote:
Hi all,

In a module I have the following structure..

Public Structure ButtonStatusFla gs

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 ButtonStatusFla gs

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




Nov 21 '05 #3
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 ButtonStatusFla gs

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 ButtonStatusFla gs.vb ---x--- Public Structure ButtonStatusFla gs

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

End Structure ---x--- end ButtonStatusFla gs.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

"Steve" <@> wrote in message
news:42******** *************** @news.optusnet. com.au... Hi all,

In a module I have the following structure..

Public Structure ButtonStatusFla gs

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 ButtonStatusFla gs

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




Nov 21 '05 #4
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 ButtonStatusFla gs

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 ButtonStatusFla gs.vb ---x--- Public Structure ButtonStatusFla gs

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

End Structure ---x--- end ButtonStatusFla gs.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

"Steve" <@> wrote in message
news:42******** *************** @news.optusnet. com.au... Hi all,

In a module I have the following structure..

Public Structure ButtonStatusFla gs

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 ButtonStatusFla gs

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




Nov 21 '05 #5

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:uP******** ******@TK2MSFTN GP10.phx.gbl...
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".


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
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2348
by: Arthur J. O'Dwyer | last post by:
I was paging through Coplien's book "Advanced C++ Programming Styles and Idioms" this afternoon and found some code that looked something like void sort(vector<foo> a) { int flip; do { for (int i=0, flip = 0; i < a.size(); ++i) {
1
2725
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on structures. Trying to comprehend this is harder than I thought it was going to be. I should of just skipped this chapter and went right into pointers since they seem to be easier to use. But anyways here i smy question: you define a structure...
8
1548
by: Hamish | last post by:
I havea program which on execution gives unpredictable behaviour (it shouldn't). In trying to track down the problem, I'm wondering if there is a difference between these two ways of filling a std::vector with data: Method 1: std::vector<int> v; int k; for(i=0;i<n;i++){
55
4650
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's not obvious how the code works if you don't know the intricacies of the Property Let/Get syntax. Likewise, I dislike (and code to minimize the use of) the VB/VBA syntax of returning a value by referring to the function name as if it were a...
2
2404
by: thomasfarrow | last post by:
At work, our development team has a development standards document that insists Structures should never be used. I'm looking to change this standard but need a suitable argument in order to make the change. I know that Structures are value types, sit on the stack, and are generally more efficient to manipulate than reference types (i.e. Classes). Structures cannot use inheritance, the finalize method or default constructors. Can anyone...
16
4812
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to keep track on the structures... But it's a bit confusing - my program won't compile and I don't know what to do about the warnings/error messages. c:\documents and settings\dell\Desktop\test\main.c(5) : warning
21
1491
by: Roland | last post by:
The following issue is puzzling me: There are 2 ways of writing the code below: .... Dim fnt as Font = New Font(...) DrawString(myText, fnt,...) fnt.dispose(). or DrawString(myText, New Font(...),...)
12
3872
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm trying to access // that has two ports. Each port has 10 sequential // registers. Create a...
18
1895
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two requests at the same time. The first one stops execution as the second continues. If I place either an alert between the two requests or run the second through a setTimeout of only 1 millisecond, they both work. You can see a working example here:...
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.