PC Review


Reply
Thread Tools Rate Thread

Calling Parent methods

 
 
TheVillageCodingIdiot
Guest
Posts: n/a
 
      29th Apr 2009
I have a base class with a sub class inside it. What im trying to do
is call a method from the parent class. the structure is like this
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Class1
private someTable as datatable

Public sub new(company as string)
someTable = 'call sub to fill datatable
end sub

protected function CompanyExists(companyName as string) as boolean
dim doesExists as boolean = false

if someTable.rows.exists(companyName) then
doesExists = true
end if

return doesExist
end function

Public Class 2
Public Sub AddEmployee(firstName as string, lastName as string,
company as string)
if CompanyExists(company) then
'run code to insert record into employee table
end if
end sub

end class
end class

------------------------------------------------------------------------------------------------------------------------------------------------------

What i would like to do in the application code is

dim cls as new class1("CompanyName")

cls.class2.AddEmployee("John", "Doe", "SomeCompany")


How do i got about calling CompanyExists from inside class 2. I dont
think inheritance would work for what im trying to do because i would
just like to create a instance of the parent class and call methods
inside the various child classes.
 
Reply With Quote
 
 
 
 
TheVillageCodingIdiot
Guest
Posts: n/a
 
      30th Apr 2009
well basically what im doing is creating a class to handle importing
users and there dependents into our database and would like to
separate the methods for importing the users and importing there
dependents. sorry about the the terminology, i did mean nested
classes. I would like to avoid having to create multiple instances in
the app code. ie not have to create a employee class and then create a
dependent class. something like this.

dim cls as new class1

cls.employee.AddEmployee("John", "Doe", "CompanyName")
cls.dependent.AddDependent("Jane", "Doe", "EmployeeID")
 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      30th Apr 2009
On Apr 30, 5:54*am, TheVillageCodingIdiot
<whosyodaddy1...@hotmail.com> wrote:
> well basically what im doing is creating a class to handle importing
> users and there dependents into our database and would like to
> separate the methods for importing the users and importing there
> dependents. sorry about the the terminology, i did mean nested
> classes. I would like to avoid having to create multiple instances in
> the app code. ie not have to create a employee class and then create a
> dependent class. something like this.
>
> dim cls as new class1
>
> cls.employee.AddEmployee("John", "Doe", "CompanyName")
> cls.dependent.AddDependent("Jane", "Doe", "EmployeeID")


If you want the syntax as above, "employee" will have to be a property
of Class1, and, most likely, you'll have to define a special class for
it, and instantiate that in Class1. There's no other way.

 
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
Calling Parent methods TheVillageCodingIdiot Microsoft Dot NET Framework 0 29th Apr 2009 07:13 PM
Access parent properties/methods? Chris Ashley Microsoft C# .NET 1 12th Oct 2005 02:31 PM
MDI Parent call MID Child events, methods Waleed Seada Microsoft C# .NET 8 27th Jan 2005 04:14 PM
Calling parent methods from a child =?Utf-8?B?Smlt?= Microsoft ASP .NET 5 13th Jan 2005 12:03 AM
referencing parent form methods John Microsoft Dot NET Framework Forms 3 4th Nov 2003 02:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:22 PM.