Hi, guys.
I'm debugging a VB program that is written by the guy who already left the company. I found out the main problem is that the guy used object assignment which will mess up the data. For example, I have a customized class as following:
And in my main program, I have:
Run the main program, I will get the message box pop up. But this is not what I want. All I want is to copy property values in cell2 to cell1, instead of reference cell2 to cell1.
Now I know I can use:
to achieve what i really want. But in real life, if the class has hundreds of properties, this is not the right way to do it. So I want to create a copy constructor as I can do in C++, anybody knows how to do it in VB?
Ben
I'm debugging a VB program that is written by the guy who already left the company. I found out the main problem is that the guy used object assignment which will mess up the data. For example, I have a customized class as following:
Code:
Public Class testCell
Private _name As String = ""
Private isCopied As Boolean = False
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property isCopy() As Boolean
Get
Return isCopied
End Get
Set(ByVal Value As Boolean)
isCopied = Value
End Set
End Property
Public Sub Reset()
_name = ""
isCopied = False
End Sub
End Class
Code:
Dim cell1 As testCell = New testCell
Dim cell2 As testCell = New testCell
cell1 = cell2
cell2.Name = "Ben"
If cell1.Name = "Ben" Then
MsgBox("Object is referenced")
End If
Now I know I can use:
Code:
cell1.Name = cell2.Name cell1.isCopy = cell2.isCopy
Ben
Comment