PC Review


Reply
Thread Tools Rate Thread

Class Hierarchy in VBA

 
 
krsone21121983@hotmail.com
Guest
Posts: n/a
 
      22nd Mar 2007
Is it possible to create a class hierarchy in VBA? If so, how do I
tell my sub class which class it extends?

Thanks for you help

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      22nd Mar 2007
Are you referring to using "Implements" ?

NickHK

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is it possible to create a class hierarchy in VBA? If so, how do I
> tell my sub class which class it extends?
>
> Thanks for you help
>



 
Reply With Quote
 
krsone21121983@hotmail.com
Guest
Posts: n/a
 
      22nd Mar 2007
yes thanks, "Implements" seems to look good from what I read in the
example in the help file. It looks like "Implements" is used for
implementing Interfaces and extending classes.

 
Reply With Quote
 
krsone21121983@hotmail.com
Guest
Posts: n/a
 
      22nd Mar 2007
Now I have another Question.

Lets say I have a class "Person" with the attributes "firstName" and
"lastName". This class has a method "print" which will return the
first and last name as a string.
Now I create a class "Employee" which implements "Person" and has an
additional attribute "salary". Now i also want to create a "print"
method for "Employee" but i dont want to do it like this:

public function print() {
print = Me.firstName & Me.lastName & Me.salary
}

instead i would like to do it like this:

public function print() {
print = super.print() & Me.salary
}

super is supposed to call the print method from the "Person" class,
since "Employee" implements "Person". However in vba i don't know how
to do this, because super doesnt work in vba. Whats the way to do this
in vba?


 
Reply With Quote
 
Norman Yuan
Guest
Posts: n/a
 
      22nd Mar 2007
VB/VBA is not a full Object-oriented language, it does not support
Inheritance, as full Object-Oriented languages do, like C++, Java, C#,
VB.NET...

So, you cannot derive a new class ona base class. That is, you cannot first
create a "Person" class, and then derive an "Employee" class on top of it.
In VB/VBA, you only have limited Inheritance capability: Implements another
class: you define a class with properties and methods (usually, there is no
code inside the properties and methods' definitions), and define a class
that implement that interface class. A class can inmplement one or more
other classes according to your need.

Note, "Implements" a class is different from "Derive" from a base class. In
true Object-oriented language, when you subclass from a base class, it
automatically gets all proerties/methods the base class has. With
"Implements", you must write code to implement all exposed property and
method definitions in the interface class (hence the word "Implements"),
which is basically the same when you implements Interfaces in Java, C++,
C#....


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Now I have another Question.
>
> Lets say I have a class "Person" with the attributes "firstName" and
> "lastName". This class has a method "print" which will return the
> first and last name as a string.
> Now I create a class "Employee" which implements "Person" and has an
> additional attribute "salary". Now i also want to create a "print"
> method for "Employee" but i dont want to do it like this:
>
> public function print() {
> print = Me.firstName & Me.lastName & Me.salary
> }
>
> instead i would like to do it like this:
>
> public function print() {
> print = super.print() & Me.salary
> }
>
> super is supposed to call the print method from the "Person" class,
> since "Employee" implements "Person". However in vba i don't know how
> to do this, because super doesnt work in vba. Whats the way to do this
> in vba?
>
>



 
Reply With Quote
 
krsone21121983@hotmail.com
Guest
Posts: n/a
 
      22nd Mar 2007
Ok thanks for the info, then ill have to work without a class hierarchy

 
Reply With Quote
 
=?Utf-8?B?Qmx1ZSBBYXJkdmFyaw==?=
Guest
Posts: n/a
 
      30th Mar 2007
Hello

Classes are a real pain in vba. But you could try doing something like this.
Lets say you want Class B to extend Class A. In the class B code write:

Implements ClassA

private super as ClassA

private sub Class_Initialize
super = new ClassA
end sub

So now classB has an internal copy of ClassA inside it and so you can make
references to that. Eg: super.print( )

(in theory it should work, but as I'm currently stuck on interfaces too then
I may not be the best person for advice!!)

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      30th Mar 2007
I think you need to read up on how Implements/Interface/classes work.
Chack the help for the Implements key word.

NickHK

"Blue Aardvark" <(E-Mail Removed)> wrote in message
news:75B9040A-265A-4671-BD8C-(E-Mail Removed)...
> Hello
>
> Classes are a real pain in vba. But you could try doing something like

this.
> Lets say you want Class B to extend Class A. In the class B code write:
>
> Implements ClassA
>
> private super as ClassA
>
> private sub Class_Initialize
> super = new ClassA
> end sub
>
> So now classB has an internal copy of ClassA inside it and so you can make
> references to that. Eg: super.print( )
>
> (in theory it should work, but as I'm currently stuck on interfaces too

then
> I may not be the best person for advice!!)
>



 
Reply With Quote
 
=?Utf-8?B?Qmx1ZSBBYXJkdmFyaw==?=
Guest
Posts: n/a
 
      30th Mar 2007
I did read up! I got that idea off a microsoft page on this website.
And if anyone else is reading this then I forgot the "set" command in my
code. It should have been:

private sub Class_Initialize
set super = new ClassA
end sub


"NickHK" wrote:

> I think you need to read up on how Implements/Interface/classes work.
> Chack the help for the Implements key word.
>
> NickHK
>
> "Blue Aardvark" <(E-Mail Removed)> wrote in message
> news:75B9040A-265A-4671-BD8C-(E-Mail Removed)...
> > Hello
> >
> > Classes are a real pain in vba. But you could try doing something like

> this.
> > Lets say you want Class B to extend Class A. In the class B code write:
> >
> > Implements ClassA
> >
> > private super as ClassA
> >
> > private sub Class_Initialize
> > super = new ClassA
> > end sub
> >
> > So now classB has an internal copy of ClassA inside it and so you can make
> > references to that. Eg: super.print( )
> >
> > (in theory it should work, but as I'm currently stuck on interfaces too

> then
> > I may not be the best person for advice!!)
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET class hierarchy GeezerButler Microsoft Dot NET Framework 7 9th Jul 2007 07:45 AM
Identifying the current class in a class hierarchy chrisp Microsoft C# .NET 2 16th Jun 2006 09:21 PM
Question about Class Hierarchy and ADO.Net Ed West Microsoft C# .NET 0 6th Oct 2004 07:28 AM
Getting data in class hierarchy (C#) MattC Microsoft ADO .NET 2 26th Jul 2004 08:30 PM
Class Hierarchy For VB/Framework etc One Handed Man [ OHM ] Microsoft VB .NET 7 4th Dec 2003 04:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:17 AM.