Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ok thanks for the info, then ill have to work without a class hierarchy
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Hierarchy table | Excel Discussion (Misc queries) | |||
Class modules: parametrize class object fields | Excel Programming | |||
Hierarchy in excel | New Users to Excel | |||
Sort by Hierarchy | Excel Programming | |||
Sum in hierarchy | Excel Programming |