Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Creating Classes in VB.NET 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith Chadwick - 27 Jul 2007 16:36 GMT
I am having some trouble understanding scope when creating my component.

Basically I have a primary class entitled permissionRights.  This class
creates several public properties of instances of other classes.  Each of the
other classes are not child classes of permisions rights.  Which is to say

public class PermissionRights
private pvPartition as new Partition
private pvDatabaseConnection as string
public readonly property Partition() as Partition
 .... return pvPartition
end property
public readonly property DatabaseConnection() as string
  ...return pvDatabaseConnection
end property
end class

public class Partition
sub new()
 dim test as new string=pvDatabaseConnection
end sub
end class

In the above code the class partition needs to access the value stored in
databaseconnection string.  Put it is not aware of it.  Now I know I can pass
it on the sub new byref but do I need to.  Both classes are in the same
project/assembly. I should be able to access the
PermissionRights.DatabaseConnection public property as a min for the current
instance.

So do I make the Partition class a sub class of permission rights.  When I
do that the code analyzer says I should make it private yet it does need to
be public?

Please help, just lost in scope at the moment :-)

Cheers
Keith
Jack Jackson - 27 Jul 2007 18:47 GMT
>I am having some trouble understanding scope when creating my component.
>
[quoted text clipped - 22 lines]
>databaseconnection string.  Put it is not aware of it.  Now I know I can pass
>it on the sub new byref but do I need to.

Yes you do.  The instance of Partition that is created in
PermissionRights has no idea that you stored a reference to it in some
PermissionRights instance.  .NET has no concept of instances belonging
to or being children of another instance.

> Both classes are in the same
>project/assembly. I should be able to access the
>PermissionRights.DatabaseConnection public property as a min for the current
>instance.

No.  .NET doesn't work that way.  There is no concept of implicit
instance references or 'current instance'.  If you want to access the
DatabaseConnection property of some instance, you need to supply a
reference to the instance.
Keith Chadwick - 27 Jul 2007 19:28 GMT
That is what I was beginning to think.  That is the way it has allways been
in VB but I thought that perhaps .NET provided that scope somehow, but I
guess not.

So still back to the good old days of passing a ref in on creation of the
class.

Thanks for the clarrification...
Cheers
Keith Chadwick

> >I am having some trouble understanding scope when creating my component.
> >
[quoted text clipped - 37 lines]
> DatabaseConnection property of some instance, you need to supply a
> reference to the instance.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.