Click to See Complete Forum and Search --> : VB 2005 Array/Loop Help


Joseph Witchard
02-24-2008, 05:36 PM
I'm trying to write code for my Visual Basic class to calculate the average of a double array names "rates".

For subscript As Integer = 1 To rates.Length – 1
Accumulator = Accumulator + Rates()
Rates(subscript) = Rates(subscript) + 1
Counter = Counter + subscript
Next subscript

Average = Accumulator / Counter


Me.xAverageLabel.Text = Convert.ToString(Average)


That was the best I could come up with, but even so, it doesn't look right to me. Anyone who has some experience with Visual Basic, I'd appreciate the help.

bflosabre91
02-26-2008, 05:03 PM
hmm, i think u might need to start the subscript as integer = 0. cause the first value in the array would be rates(0). and i believe you are skipping that one.

if ur still having problem, maybe could you post an example of the field values and what you getting as the result.
good luck