Hi!
I hope i do post in the right forum now.
I have som problems with arrays. I want to take array1 and array2 and take out the mean value of them, for each number. The textfile have 10 numbers included, and array2 is just reversed. So it looks like this:
And I want array3 to be (45 + 2 / 2) and etc.
This is my code, and I hope that someone could help me out.
I hope i do post in the right forum now.
I have som problems with arrays. I want to take array1 and array2 and take out the mean value of them, for each number. The textfile have 10 numbers included, and array2 is just reversed. So it looks like this:
VB.NET:
Array1 Array2
45 2
56 82
89 65
12 34
78 53
53 78
34 12
65 89
82 56
2 45
And I want array3 to be (45 + 2 / 2) and etc.
This is my code, and I hope that someone could help me out.
VB.NET:
Dim array1(9), array2(9), array3(9) As Integer
Function InitArray(ByVal arr() As Integer, ByVal filSpec As String) As Integer()
Dim sr As IO.StreamReader
Dim i As Integer
sr = IO.File.OpenText(filSpec)
For i = 0 To arr.GetUpperBound(0)
arr(i) = sr.ReadLine
Next
sr.Close()
Return arr
End Function
Function ReadArray(ByVal arr() As Integer) As String
Dim i As Integer, s As String
For i = 0 To arr.GetUpperBound(0)
s &= arr(i) & Chr(13) & Chr(10)
Next
Return s
End Function
Function ReverseArray(ByVal arr() As Integer) As String
Dim i As Integer, reversed As String
Array.Reverse(arr)
For i = 0 To arr.GetUpperBound(0)
reversed &= arr(i) & Chr(13) & Chr(10)
Next i
Return reversed
End Function
Function MeanArray(ByVal arr() As Integer) As String
[B][COLOR="Red"]HOW?[/COLOR][/B]
End Function
Private Sub btnFirstArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstArray.Click
txtArray1.Text = ReadArray(InitArray(array1, "Array2_1.txt"))
txtArray2.Text = ReverseArray(InitArray(array2, "Array2_1.txt"))
txtArray3.Text = MeanArray(InitArray(array3, "Array2_1.txt"))
End Sub
Last edited by a moderator: