Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Class Hierarchy in VBA

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Class Hierarchy in VBA

Are you referring to using "Implements" ?

NickHK

wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Class Hierarchy in VBA

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Class Hierarchy in VBA

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?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Class Hierarchy in VBA

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#....


wrote in message
ups.com...
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?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Class Hierarchy in VBA

Ok thanks for the info, then ill have to work without a class hierarchy

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hierarchy table Derrick Excel Discussion (Misc queries) 1 October 31st 08 01:53 AM
Class modules: parametrize class object fields Jean-Pierre Bidon Excel Programming 11 August 31st 06 02:49 PM
Hierarchy in excel jamshaggy New Users to Excel 1 July 23rd 06 06:49 PM
Sort by Hierarchy SpaceCamel Excel Programming 1 February 26th 06 08:52 AM
Sum in hierarchy hideki[_26_] Excel Programming 3 February 23rd 06 06:24 PM


All times are GMT +1. The time now is 01:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"