Inheriting Classes from another VB.NET project(s)
Hi experts
I am VERY new to DOTNET so pardon my knowledge.
Can we inherit classes from other VB Projects in DOTNET?
Because I have a VB DOT NET Source Code Project and I need to implement its standard Interfaces and Inherit some classes in my new VB project.
I dont want to make DLL of that API project and refrrering it in my project to make its COM like objects for the reason that I think that way I wont be able to use its Interfaces [If I am Correct?] :o Hence the question.
I use VS-DOTNET 2005.
Re: Inheriting Classes from another VB.NET project(s)
Yes, you can... but you either have to compile everything in to one assembly, or you need to compile it in to a separate assembly and reference it.
Re: Inheriting Classes from another VB.NET project(s)
Quote:
Originally Posted by Craig Gemmill
Yes, you can... but you either have to compile everything in to one assembly, or you need to compile it in to a separate assembly and reference it.
Thx Craig. But I have already done that
Which reference r u talking about?
I had a project Vehicle with a VB class Vehicle (that has 2 functions defined in it).
I have another project Car that has VB class Car that Inherits Vehicle and its 2 functions.
Vehicle directory and Car directory exist diferently on the hard disks.
Now in Car project I add Vehicle Project to make a Parent Assembly Car. Thus this parent assembly has 2 projects Car and Vehicle each showing their respective classes. But still in my Car project's Car class I see
Class Car
Inherits Vehicle
showing Vehicle as Unknown Identifier.
Parent Assembly Car when right clicked and chosen properties, properly shows Vehicle as the referenced project.
Oh and BTW Vehcile was successfully build for its DLL. So now we have 2 options. Either Vehicle project Or vehicle Dll. My problem is I have to INHERIT Vehicle Class in Car.
Thx.
Re: Inheriting Classes from another VB.NET project(s)
Sounds like you need to use the correct namespace to reference VEHICLE. So instead of doing this:
Inherits Vehicle
You might have to use:
Inherits Project2.Vehicle
Where Project2 is the name of the project/library that contains the VEHICLE definition.
Open the Object Browser in Visual Studio. It will show you all the relationships among objects.
1 Attachment(s)
Re: Inheriting Classes from another VB.NET project(s)
Hi Craig,
I tried referring it by NameSpace but no use.
Can you please have a look at my code and help me .... Its a Zipped copy named ProjectReference.zip with 2 folders in it ... one is Vehicle project and other is Car project made in MS-DOTNET 2005. The two are already linked and hopefully be linked when opened on your machine!( :) )
What I do is .....
1. Build Vehicle project for its DLL with successful compilation.
2. Open Car project and select the project name from Solution Explorer and from Menu ......... File->Add-> Existing project, I add Vehicle vbproject from Vehicle folder into Car project.
This makes Car the parent assembly showing 2 projects Car and Vehicle resp.
Now open Car.vb class and see that is in Error although Car project has proper reference to Vehicle. :confused:
Re: Inheriting Classes from another VB.NET project(s)
Ok, in your Car project references: Add a reference to the PROJECT Vehicle. Then your Car code should look like this:
Code:
Public Class Car
Inherits Vehicle.Vehicle
Public Overrides Sub ApplyBreaks()
End Sub
End Class
I know it works, so keep trying until you get it.
Re: Inheriting Classes from another VB.NET project(s)
Oh my god! :eek:
I have been going thru the same UIs for a week now, but never tried adding PROJECT Vehicle reference into generic references of Car.
I would access the projects tab of Car Add Refernce window and would always see vehicle shown there. thus thinking that Vehicle is already referred. But never tried referencing Vehicle explicitly to the Car project's generic refernces.
That was a relief!
Thx Craig
:thumb:
Re: Inheriting Classes from another VB.NET project(s)
I just want to add that naming a class in the same name as the namespace is a very bad idea, and can causeyou problems in the future.