By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

How to execute parent class functions and then child's

P: n/a
How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. How should I
declare classes so that all three functions are executed when child
class is called?

Class Parent
public function ONE
'code
end fuction

public function TWO
'code
end fuction
end class

Class Child
Inherites Parent

public function THREE
'code
end fuction
end class

Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
<ms****@yahoo.com> schrieb
How to execute functions in the parent class first and then
functions in the child class? For example, I have a parent class
with functions 'ONE' and 'TWO' and child class has a function
'THREE'. How should I declare classes so that all three functions
are executed when child class is called?

Class Parent
public function ONE
'code
end fuction

public function TWO
'code
end fuction
end class

Class Child
Inherites Parent

public function THREE
'code
end fuction
end class


public function THREE
ONE
TWO
end fuction
That's what you need?

Armin
Nov 21 '05 #2

P: n/a
Hi,

I don't know if I understood you.

However you can set in the Sub New of your parent class

\\\
Public Sub New
ONE
TWO
End Sub
///

I hope this was what you where after

Cor
Nov 21 '05 #3

P: n/a
After some thought, this is what I would like to have. I am sorry to
both of you.
I have a parent class and child class. When I execute function ONE
from child class, is it going to executes parent's code plus child's
code? How should I declare or inherite a classe so that it executes
parent's code and then child's code?

Example:
Class Parent

public function ONE
'Parent Code
end fuction
end class
Class Child
Inherites Parent

public function ONE
'Plus Child Code
end fuction
end class


msx...@yahoo.com Jun 6, 11:27 am show options

Newsgroups: microsoft.public.dotnet.languages.vb
From: msx...@yahoo.com - Find messages by this author
Date: 6 Jun 2005 08:27:48 -0700
Local: Mon,Jun 6 2005 11:27 am
Subject: How to execute parent class functions and then child's
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. How should I
declare classes so that all three functions are executed when child
class is called?

ms****@yahoo.com wrote:
How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. How should I
declare classes so that all three functions are executed when child
class is called?

Class Parent
public function ONE
'code
end fuction

public function TWO
'code
end fuction
end class

Class Child
Inherites Parent

public function THREE
'code
end fuction
end class


Nov 21 '05 #4

P: n/a
Msxkim,

It depends if one is a function that always should be performed in that
class, than in the way as I wrote. Is it not standard in that class, than in
the way as Armin wrote.

Cor
Nov 21 '05 #5

P: n/a
<ms****@yahoo.com> schrieb
After some thought, this is what I would like to have. I am sorry
to both of you.
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code? How should I declare or inherite a classe so that it
executes parent's code and then child's code?

Example:
Class Parent

public function ONE
'Parent Code
end fuction
end class
Class Child
Inherites Parent

public function ONE
'Plus Child Code
end fuction
end class

Class Child
Inherites Parent

public function ONE
MYBASE.one
'Plus Child Code
end fuction
end class
Armin
Nov 21 '05 #6

P: n/a
Bingo! both of you

Armin Zingler wrote:
<ms****@yahoo.com> schrieb
After some thought, this is what I would like to have. I am sorry
to both of you.
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code? How should I declare or inherite a classe so that it
executes parent's code and then child's code?

Example:
Class Parent

public function ONE
'Parent Code
end fuction
end class
Class Child
Inherites Parent

public function ONE
'Plus Child Code
end fuction
end class

Class Child
Inherites Parent

public function ONE
MYBASE.one
'Plus Child Code
end fuction
end class
Armin


Nov 21 '05 #7

P: n/a
<ms****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code?


It depends. ;-)

Given these :

Class Parent
Public Sub ONE()
Debug.Writeline( "Parent.ONE" )
End Sub
End Class

Class Child
Inherits Parent
End Class

then

Dim c As New Child
c.ONE()

will display "Parent.ONE" - the child class is simply "passing on" the
Parent class' functionality.

However, changing these classes a little :

Class Parent
Public Overridable Sub ONE()
Debug.Writeline( "Parent.ONE" )
End Sub
End Class

Class Child
Inherits Parent
Public Overrides Sub ONE()
Debug.Writeline( "Child.ONE" )
End Sub
End Class

then

Dim c As New Child
c.ONE()

now displays "Child.ONE". The Child mothod replaces (a.k.a.
Overrides) the Parent method.

<--
And, just to be /really/ confusing, try this and see what you get ...

DirectCast( c, Parent ).ONE() ' ;-)
-->

To get /both/ sets of code to run, you make the Child method
call the Parent one, as in

Class Child
Inherits Parent
Public Overrides Sub ONE()
MyBase.ONE()
Debug.Writeline( "Child.ONE" )
End Sub
End Class

which (finally) displays "Parent.ONE" followed by "Child.ONE".

HTH,
Phill W.
Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.