How do I concate two Classes question

Hello all, Suppose I have Class_A with 10 properties and Class_B which overrides Class_A and adds 4 properties.
So Class_B has 14 properties. (I have this working)

But in code I have an instance of Class_A and need to create an instance of Class_B and for this instance add the 4 properties.

My program is a invoice program and Class_A is a product and Class_B is an invoice line.

Thanks in advance,
Brian

mmm the problem you stated is not very clear to me.

You have an “A” class, invoice, and a “B” class, which corresponds to an invoice line.

Well, at most, in A, you can have an array of rows (B).

But, from how you’ve spelled it all out, having “B inheriting from A” looks wrong

I am sorry I wasn’t clear.
Class_A is a product. (in a listboxRow.tag) the user selects the listboxRow and now I need to add the Class_A into a Class_B (which contains the extra properties: Price and Quantity)

I believe by “add” you mean having the values ​​you already have in class A object, inside class B object. I think you can achieve this by creating a “copy constructor” method

That is exactly what I mean.
But I googled Copy Constructor and could only find something in Monkeybread software.
Do you have a tip or some link or some help, please.

But you can very well build it yourself.

in class “B” add a method “PopulateByProduct” which takes as parameter an object of class “A”.

The implementation of the method is simple:

Me.field1 = objectTo.field1

Me.field2 = objectTo.field2

and so on

YES, I see it now (in my head)
Class_B.PopulateByProduct(Class_A)

Thank you.

May the object A die while B still around? If not, why not just linking both and when inspecting B you could just read the linked A.

Public ClassA

  Public val1 As String
  Public val2 As String

End Class

Public ClassB
  Public val1 As Integer
  Public val2 As Integer
  Public A As ClassA

  Public Sub Constructor(objA As ClassA)
    A = objA 
  End Proc

End Class

Var A As New ClassA
A.val1 = "aaaa"

Var B As New ClassB(A)

MessageBox B.A.val1 // show "aaaa"

This is even more beautiful code.
I think this would make my code easier to understand and read after a few years.

Thank you.
(As a joke → To other readers please do not give any other better solutions. This is the 4th time I rewrite this code. Two didn’t work, one is the above answer from Ant and now this one)

Theoretically, if object A is encapsulated in B, as long as B exists, A will also exist, so you might be comfortable with that (I’m not 100% sure)

I guess his design allows his choice, as holding the reference to it was warned before as you see. As soon as B dies too, A will released, since its lifecycle has ended, where all references to it are gone.