CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2003
    Location
    Mumbai, Maharashtra INDIA
    Posts
    20

    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?] Hence the question.

    I use VS-DOTNET 2005.
    V.V.Sankhe

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow 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.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Oct 2003
    Location
    Mumbai, Maharashtra INDIA
    Posts
    20

    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.
    Last edited by vinitsankhe; October 21st, 2006 at 03:02 PM.
    V.V.Sankhe

  4. #4
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow 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.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  5. #5
    Join Date
    Oct 2003
    Location
    Mumbai, Maharashtra INDIA
    Posts
    20

    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
    Code:
    Inherits Vehicle
    is in Error although Car project has proper reference to Vehicle.
    Attached Files Attached Files
    V.V.Sankhe

  6. #6
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow 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.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  7. #7
    Join Date
    Oct 2003
    Location
    Mumbai, Maharashtra INDIA
    Posts
    20

    Re: Inheriting Classes from another VB.NET project(s)

    Oh my god!

    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

    V.V.Sankhe

  8. #8
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured