Hello, all:
I'm new to the VB.NET world and am trying to pass a structure array to a function and have it pass me back a new structure array with update values. Everything in the code below seems to work fine, the returned structure array is perfect, but it also changes the original. What am I doing wrong?!
Public Class Form1
Structure SpaceCurve
Dim x As Double
Dim y As Double
Dim SpaceName As String
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim n As Integer
Dim OrigSC(10) As SpaceCurve
Dim WorkSC(10) As SpaceCurve
For n = 0 To 10
OrigSC(n).x = n * 1.5
OrigSC(n).y = n * 2.5
OrigSC(n).SpaceName = "Space" & CStr(n)
Console.WriteLine(OrigSC(n).x & "," & OrigSC(n).y & "," & OrigSC(n).SpaceName)
Next
WorkSC = UpdateSC(OrigSC, "-test")
For n = 0 To 10
Console.WriteLine(WorkSC(n).x & "," & WorkSC(n).y & "," & WorkSC(n).SpaceName)
Next
For n = 0 To 10
Console.WriteLine(OrigSC(n).x & "," & OrigSC(n).y & "," & OrigSC(n).SpaceName)
Next
End Sub
Function UpdateSC(ByVal SCStruct() As SpaceCurve, ByVal SpaceAppend As String) As SpaceCurve()
Dim x As Integer
For x = 0 To UBound(SCStruct)
SCStruct(x).x = 1.0
SCStruct(x).y = 3.3
SCStruct(x).SpaceName = SCStruct(x).SpaceName & SpaceAppend
Next
UpdateSC = SCStruct
End Function
End Class
Console...
0,0,Space0
1.5,2.5,Space1
3,5,Space2
4.5,7.5,Space3
6,10,Space4
7.5,12.5,Space5
9,15,Space6
10.5,17.5,Space7
12,20,Space8
13.5,22.5,Space9
15,25,Space10
1,3.3,Space0-test
1,3.3,Space1-test
1,3.3,Space2-test
1,3.3,Space3-test
1,3.3,Space4-test
1,3.3,Space5-test
1,3.3,Space6-test
1,3.3,Space7-test
1,3.3,Space8-test
1,3.3,Space9-test
1,3.3,Space10-test
1,3.3,Space0-test
1,3.3,Space1-test
1,3.3,Space2-test
1,3.3,Space3-test
1,3.3,Space4-test
1,3.3,Space5-test
1,3.3,Space6-test
1,3.3,Space7-test
1,3.3,Space8-test
1,3.3,Space9-test
1,3.3,Space10-test