Discussion on:

Message 11 of 18
0 Votes
+ -
Oh.... hmmmm
I'll have to think about that....


-Edit
This is what I figured out, I don't like that it doesn't include the current index. I think the real answer is 5, but to get 3 I exclude the current index in the math.
I wrote in in VB6 just cause I had the IDE open at the time

Option Explicit

Private Sub Form_Load()
Dim aTest(0 To 6) As Double
Dim i As Double
Dim iAnswer As Double

aTest(0) = -7
aTest(1) = 1
aTest(2) = 5
aTest(3) = 2
aTest(4) = -4
aTest(5) = 3
aTest(6) = 0

iAnswer = 1
For i = LBound(aTest) + 1 To UBound(aTest) - 1 Step 1
If SumArray(aTest, LBound(aTest), i - 1) = SumArray(aTest, i + 1, UBound(aTest)) Then
iAnswer = i
Exit For
End If
Next i

Call MsgBox(iAnswer)


End Sub

Private Function SumArray(ByRef arr() As Double, iFromIndex As Double, iToIndex As Double) As Double
Dim i As Double
Dim sum As Double
For i = iFromIndex To iToIndex Step 1
sum = sum + arr(i)
Next i
SumArray = sum
End Function

Posted by Slayer_
Updated - 16th Nov