nested classes and properties and imports inherits implements

  • Thread starter Thread starter nottarealaddress
  • Start date Start date
N

nottarealaddress

(VB 2005)
I'm trying to end up with some nested properties for my MasterMDI
form.These will be boolean variables that will be read in at load time
and used throughtout the lifecycle of the application.

I already know how to create Properties for a form so that I can
reference and set, for example:
Me.Read = True
Me.Write = False
(I do this the redundant way, adding the property in each form.)

What I'd like to end up with is:
Me.Aspect1.Read = True
Me.Aspect1.Write = False
......
Me.Aspect7.Read = False
Me.Aspect7.Write = False

If it can't be done, then I'll just use (Note the lack of dots):
Me.Aspect1Read = True
Me.Aspect1Write = False
......
Me.Aspect7Read = False
Me.Aspect7Write = False

Why? Because there are 9 different aspects and there's not just Read &
Write, there's also Edit and Delete AND if I can get this to work I'll
have very reusable code for the future. This is something we're going
to be doing over and over in our future applications, which will have
dozens of Aspects, so I really only have this app as a learning curve.

I was experimenting with various imports and inherits statements, but
in not knowing what I'm doing, I blew out the MasterMDI form and now
it won't display in Design mode. It's icon has even changed from a
Form to something that's just VBCode (Note the difference between a
form and a module.) The design window only shows up as text and it's
got LOTS of errors.

Now I have to create a new MasterMDI and salvage what I can from the
old one before tackling this issue again. (I know: It's my own fault--
Back Up! Back Up! Back Up!)

Now, I'm a little gun-shy about trying this again without some outside
direction.

The other IMPORTANT info is do I use Imports/Inherits/Implements and
where do I place the statements:
<--Here?
Public Class frmMasterMDI
<--Here?
Dim str As String
<--Here?
Private Sub Button_Click
End Sub
End Class

I think once I find this out, I will be better able to wrap my head
around VB.NET
Thank you in Advance,
-Scott
 
(VB 2005)
I'm trying to end up with some nested properties for my MasterMDI
form.These will be boolean variables that will be read in at load time
and used throughtout the lifecycle of the application.

I already know how to create Properties for a form so that I can
reference and set, for example:
Me.Read = True
Me.Write = False
(I do this the redundant way, adding the property in each form.)

What I'd like to end up with is:
Me.Aspect1.Read = True
Me.Aspect1.Write = False
.....
Me.Aspect7.Read = False
Me.Aspect7.Write = False

If it can't be done, then I'll just use (Note the lack of dots):
Me.Aspect1Read = True
Me.Aspect1Write = False
.....
Me.Aspect7Read = False
Me.Aspect7Write = False

Why? Because there are 9 different aspects and there's not just Read &
Write, there's also Edit and Delete AND if I can get this to work I'll
have very reusable code for the future. This is something we're going
to be doing over and over in our future applications, which will have
dozens of Aspects, so I really only have this app as a learning curve.

You can define a Public Class Aspect with the various properties, then
in the main class define properties of type Aspect. If you want to
modify these properties at design time, it will take some more effort,
but I gather you don't want to do that.
I was experimenting with various imports and inherits statements, but
in not knowing what I'm doing, I blew out the MasterMDI form and now
it won't display in Design mode. It's icon has even changed from a
Form to something that's just VBCode (Note the difference between a
form and a module.) The design window only shows up as text and it's
got LOTS of errors.

Now I have to create a new MasterMDI and salvage what I can from the
old one before tackling this issue again. (I know: It's my own fault--
Back Up! Back Up! Back Up!)

Now, I'm a little gun-shy about trying this again without some outside
direction.

The other IMPORTANT info is do I use Imports/Inherits/Implements and
where do I place the statements:
<--Here?
IMPORTS should go at the top of the file.
Public Class frmMasterMDI
Inherits ... (but see below)
Implements ...
Implements ...
<--Here?
Dim str As String
(I prefer to use explicit scopes here, Private in this case, instead
of Dim, to make it clearer what the scope really is.)
<--Here?
Private Sub Button_Click
End Sub
End Class

I think once I find this out, I will be better able to wrap my head
around VB.NET
Thank you in Advance,
-Scott

For visual classes you should use the IDE to create the right kind of
class, rather than using Inherits, to insure that the IDE generates
the correct code in the hidden designer file.
 
I'm not as far as the visual classes, yet.

At first, I tried to add a Class s/t like:

Public Class Aspect1
Dim boolRead As Boolean = False
Dim boolWrite As Boolean = False
....
Public Property Read() As Boolean
Get
Return boolRead
End Get
Set(ByVal Value As Boolean)
Me.boolRead = Value
End Set
End Property
....
End Class

(Same for Aspect2)

Then tried to add both into my form.

All I could get was
Me.Read
instead of
Me.Aspect1.Read

When I added Aspect2, the design interface complained of "overloaded"
properties.

No, you're right, I don't want to Modify then at run-time except to do
Sets and Gets.
-Scott
 
I'm not as far as the visual classes, yet. And no, I don't want to
modify the properites at run-time, with the exception of Set and Get.
(Otherwise there's no point!)

At first, I tried to add a Class s/t like:

Public Class Aspect1
Dim boolRead As Boolean = False
Dim boolWrite As Boolean = False
....
Public Property Read() As Boolean
Get
Return boolRead
End Get
Set(ByVal Value As Boolean)
Me.boolRead = Value
End Set
End Property
....
End Class


(Same for Aspect2)


Then tried to add both into my form.


All I could get was
Me.Read
instead of
Me.Aspect1.Read


When I added Aspect2, the design interface complained of "overloaded"
properties.

The next thing I tried is:

Public Class ReadWriteEditDelete
Dim boolRead as boolean = False
Public Property Read....
....(set/get--see syntax, above)...
End Class
--------------------
Imports NameSpace.ReadWriteEditDelete
Public Class Aspect1
End Class
-------------------
Imports NameSpace.Aspect1
Imports NameSpace.Aspect2
......
Public Class AllAspects
End Class
-------------------
Imports NameSpace.AllAspects
Public Class frmMDIMaster
(Master Form Coding)
End Class

But doing it this way, I didn't get access to the Read and Write
properties anymore--Me.Aspect1.Read doesn't exist, nor does Me.Read
exist anymore.

Is the solution to do with TypeOf and DirectCast, so that I can
different Reads and Writes (.Aspect1.Read .Aspect2.Read) in the same
"Me"

-Scott
 
I'm not as far as the visual classes, yet.

At first, I tried to add a Class s/t like:

Public Class Aspect1
Dim boolRead As Boolean = False
Dim boolWrite As Boolean = False
...
Public Property Read() As Boolean
Get
Return boolRead
End Get
Set(ByVal Value As Boolean)
Me.boolRead = Value
End Set
End Property
...
End Class

(Same for Aspect2)

Then tried to add both into my form.

All I could get was
Me.Read
instead of
Me.Aspect1.Read

When I added Aspect2, the design interface complained of "overloaded"
properties.

No, you're right, I don't want to Modify then at run-time except to do
Sets and Gets.
-Scott

From your original description, MasterMDI is a form, which is a visual
class (a class that has a visual representation).

I asked if you wanted to modify the properties at design time. If so,
you will need to add some design-time attributes to the properties and
possibly code.

Public Class Aspect
Private m_read As Boolean = False
Private m_write As Boolean = False
....
Public Property Read() As Boolean
Get
Return m_read
End Get
Set(ByVal Value As Boolean)
m_read = Value
End Set
End Property
....
End Class

In MasterMDI:

Private m_aspect1 As Aspect
Private m_aspect2 As Aspect
...

Public Property Aspect1() As Aspect
Get
Return m_aspect1
End Get
Set(ByVal Value as Aspect)
m_aspect1 = Value
End Set
End Property
Public Property Aspect2() As Aspect
...
 
Jack,

Apologies if I'm using incorrect terminology. (It seems nowadays as if
we get one or two apps built then move to another development
platform!)

I'm going to have to take this weekend to wrap my head the code you
were kind enough to post. It looks like what I'm aiming for. Also, the
"m_" prefix has me curious as what that implies since I've just
noticed it as "m_ChildFormNumber" in the MDIParent form.

Thanks,
-Scott
 
Jack,

Apologies if I'm using incorrect terminology. (It seems nowadays as if
we get one or two apps built then move to another development
platform!)

I'm going to have to take this weekend to wrap my head the code you
were kind enough to post. It looks like what I'm aiming for. Also, the
"m_" prefix has me curious as what that implies since I've just
noticed it as "m_ChildFormNumber" in the MDIParent form.

Thanks,
-Scott

When you have a public property with a private variable to hold its
contents, you can't name both the same. With C# you can make their
case different. With VB you can't do that because VB is case
insensitive, so one common way to deal with this is to put m_ on front
of the private variable. There is nothing magic about using m_.
 
When you have a public property with a private variable to hold its
contents, you can't name both the same. With C# you can make their
case different. With VB you can't do that because VB is case
insensitive, so one common way to deal with this is to put m_ on front
of the private variable. There is nothing magic about using m_.

Gotcha! It's the same as prefixing the Booleans with bool, Integers
with int, etc.

Hopefully without getting too personal, I'm sitting here after all my
housework is done, showered, TV off. I'm physically relaxed and I've
had time to wrap my head around the code sample you provided, tweaked
the names to my application (it makes more sense to me when used in a
particular application). It worked like a charm. I coded it, and I
started to enter a line of code to test it. When I got to
"Me.Aspect1.Read =" , Intellisense popped up with a little choice menu
consisting of True and False--exactly what I was looking for. And this
concept will be so useful for other things.

All I can say is SWEEEEEEEEEEEEEEEEEEEEEEEEEEEEET! (And I've never had
the urge to say that before!)

This is a high-profile application and the first one I'm doing in
VB2005. You are going to make job so much easier and now I feel I can
get this project into roll-out before my surgery as my boss wants.
(New hip, so I'll be out maybe 4-6 weeks.)

Thank you for taking the time to walk me through these new concepts!
-Scott
 
Back
Top