kennedymr2
Programmer
I am having (I think!) a maths problem in VB
When i run the following i get this result
1. % works out to 117.837121212
2. % should be 100.000% but works out to 100.9082259
Is my problem the way decimal points calculate in vb, OR
!!maybe! my maths formula is DUD!!!
=========================
Private Sub Command123_Click()
Dim test(6) As Double
test(0) = 22
test(1) = 3
test(2) = 8
test(3) = 0
test(4) = 32
test(5) = 2
test(6) = 12
Dim accum, accumx, accumc As Double
accum = 0
For ll = 0 To 6
If test(ll) > 0 Then
accumx = test(ll)
accum = accum + (100 / accumx + 1)
End If
Next ll
MsgBox (accum)
'Now reduce to 100%
For ll = 0 To 6
If test(ll) > 0 Then
test(ll) = test(ll) / 100 * accum
End If
Next ll
accum = 0
For ll = 0 To 6
If test(ll) > 0 Then
accumx = test(ll)
accum = accum + (100 / accumx + 1)
End If
Next ll
MsgBox (accum)
End Sub
When i run the following i get this result
1. % works out to 117.837121212
2. % should be 100.000% but works out to 100.9082259
Is my problem the way decimal points calculate in vb, OR
!!maybe! my maths formula is DUD!!!
=========================
Private Sub Command123_Click()
Dim test(6) As Double
test(0) = 22
test(1) = 3
test(2) = 8
test(3) = 0
test(4) = 32
test(5) = 2
test(6) = 12
Dim accum, accumx, accumc As Double
accum = 0
For ll = 0 To 6
If test(ll) > 0 Then
accumx = test(ll)
accum = accum + (100 / accumx + 1)
End If
Next ll
MsgBox (accum)
'Now reduce to 100%
For ll = 0 To 6
If test(ll) > 0 Then
test(ll) = test(ll) / 100 * accum
End If
Next ll
accum = 0
For ll = 0 To 6
If test(ll) > 0 Then
accumx = test(ll)
accum = accum + (100 / accumx + 1)
End If
Next ll
MsgBox (accum)
End Sub