VB6 you can do record=record.
Apparently under .NET you can't, or at least in the version of VS.NET I'm using. It breaks.
Symptom reproduction...
PublicStructure Data_Record
Public Key_Result() AsLong
Public Key_Size AsLong
Public Key_OP AsByte
Public Key_IP AsByte
Public Distance AsLong
Public Palindrome AsString
Public Lychrel_Chain AsString
Public Hits AsLong
EndStructure
Sub Main()
Dim ll AsLong
Dim a() As Data_Record
ReDim a(5)
For ll = 1 To 5
ReDim a(ll).Key_Result(1)
Next ll
a(1).Key_Size = 1
a(1).Key_Result(1) = 1
a(2) = a(1)
a(2).Key_Size = 2
a(2).Key_Result(1) = 2
a(3) = a(2)
a(3).Key_Size = 3
a(3).Key_Result(1) = 3
End Sub
If I throw a watch on array 'a' I get what I believe is a pointer assignment problem internally to the array structure affecting the value of the changing .key_result.
a(1).key_size=1
a(1).key_result(1)=3
a(2).key_size=2
a(2).key_result(1)=3
a(3).key_size=3
a(3).key_result(1)=3
The same code in VB6 produces...
a(1).key_size=1
a(1).key_result(1)=1
a(2).key_size=2
a(2).key_result(1)=2
a(3).key_size=3
a(3).key_result(1)=3
Which is the correct assignment of values. VS.NET for some reason literally as far as I can tell is pointing the second dynamic array of all prior records affected by a record=record that were done so in succession of eachother to the value of the last record=record assignment.
I tried array.copy also, and it failed the same way.
Ultimately a(2).key_result = a(1).key_result and progressing them directly without doing a direct a(2)=a(1) reference, maintains the integrity of the seperation and no corruption of data occurs in the .key_result dynamic array. I guess if I have to just bloat the code to circumvent this, then so be it... but I was hoping for .NET to be a little more gracious.
Any ideas? The SP for VS2005 didn't fix this issue. And I've not been able to find any references to this anywhere. Did this suddenly become bad coding methodology in .NET, or have I found an uncorrected/unrecognized bug?
Can anyone with a later version of VS.NET report if this mangling of array structures still occurs in 2008, or 2010? This is just one of many troubling concerns I have with making the transition to .NET from VB6.0, regardless of the fact that VB6.0 is at its end of life cycle, at least it works correctly. I get some things are easier in .NET, but what good is ease of use, if the language itself seems to be so picky about how you assign variables?
Apparently under .NET you can't, or at least in the version of VS.NET I'm using. It breaks.
Symptom reproduction...
PublicStructure Data_Record
Public Key_Result() AsLong
Public Key_Size AsLong
Public Key_OP AsByte
Public Key_IP AsByte
Public Distance AsLong
Public Palindrome AsString
Public Lychrel_Chain AsString
Public Hits AsLong
EndStructure
Sub Main()
Dim ll AsLong
Dim a() As Data_Record
ReDim a(5)
For ll = 1 To 5
ReDim a(ll).Key_Result(1)
Next ll
a(1).Key_Size = 1
a(1).Key_Result(1) = 1
a(2) = a(1)
a(2).Key_Size = 2
a(2).Key_Result(1) = 2
a(3) = a(2)
a(3).Key_Size = 3
a(3).Key_Result(1) = 3
End Sub
If I throw a watch on array 'a' I get what I believe is a pointer assignment problem internally to the array structure affecting the value of the changing .key_result.
a(1).key_size=1
a(1).key_result(1)=3
a(2).key_size=2
a(2).key_result(1)=3
a(3).key_size=3
a(3).key_result(1)=3
The same code in VB6 produces...
a(1).key_size=1
a(1).key_result(1)=1
a(2).key_size=2
a(2).key_result(1)=2
a(3).key_size=3
a(3).key_result(1)=3
Which is the correct assignment of values. VS.NET for some reason literally as far as I can tell is pointing the second dynamic array of all prior records affected by a record=record that were done so in succession of eachother to the value of the last record=record assignment.
I tried array.copy also, and it failed the same way.
Ultimately a(2).key_result = a(1).key_result and progressing them directly without doing a direct a(2)=a(1) reference, maintains the integrity of the seperation and no corruption of data occurs in the .key_result dynamic array. I guess if I have to just bloat the code to circumvent this, then so be it... but I was hoping for .NET to be a little more gracious.
Any ideas? The SP for VS2005 didn't fix this issue. And I've not been able to find any references to this anywhere. Did this suddenly become bad coding methodology in .NET, or have I found an uncorrected/unrecognized bug?
Can anyone with a later version of VS.NET report if this mangling of array structures still occurs in 2008, or 2010? This is just one of many troubling concerns I have with making the transition to .NET from VB6.0, regardless of the fact that VB6.0 is at its end of life cycle, at least it works correctly. I get some things are easier in .NET, but what good is ease of use, if the language itself seems to be so picky about how you assign variables?
Last edited: