Posted on 2005-03-29
Medium Priority
Last Modified: 2010-05-18
I have the following vb.net code:

Public Class CSipLine
    Inherits CPhoneLine

    Property SIPDomain as string

end class


Public Class CPhoneLine
    Property AccountBalance as decimal

end class

now i would like to be able to do something like this:

Dim PhoneLine as new CPhoneLine

PhoneLine.Balance = 10

Dim SIPLine as new CSIPLine

SIPLine = PhoneLine

SIPLine.SIPDomain = "test"

this code gets an error, saying invalid type cast.

what i want to achieve is assign a SIPLine object with a PhoneLine object, and essentially copy all data from phoneline into sipline object.  how can this be done?


Question by:xorcrack
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 12

Expert Comment

ID: 13654456
Which of the two classes is the "simple" one... from which the other is based (inherits it's properties from)?
LVL 12

Expert Comment

ID: 13654464
Ahhh sorry... i missed a line there... ignore my last comment
LVL 34

Accepted Solution

Brian Crowe earned 2000 total points
ID: 13654502
You could create a Copy procedure in CSipLine that takes a CPhoneLine parameter and copy the appropriate members.

Author Comment

ID: 13654516
thats what i was thinking about.  i was just wondering if there was a more elegant way?
LVL 12

Expert Comment

ID: 13654990
A cheap work around (if there is no other way other than passing the sub class as a parameter)... would be not to use inherittance and use a property instead:

Public Class SimpleClass
    Private _SomeText As String

    Public ReadOnly Property SomeText() As String
            Return _SomeText
        End Get
    End Property
End Class

Public Class ComplexClass
    Public BaseClass As SimpleClass

    Public Sub New()
        BaseClass = New SimpleClass
    End Sub

    Public Sub New(ByVal PassedBase As SimpleClass)
        BaseClass = PassedBase
    End Sub

    Public ReadOnly Property SomeText() As String
            Return BaseClass.SomeText
        End Get
    End Property
End Class


The ComplexClass.SomeText property  is not required... as it is accessible  through  ComplexClass.BaseClass.SomeText .... but just a quicker way of accessing it

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question