find the average value from a column of values
For this code I wanted to find the average of many numerical values in a column (CategoryA) in a table. First I found the number of record/values in CategoryA which is held in the variable iRecordCount. Then I made an array to gather all the values in the column which is held in ARR1(). Then I had a series of if then statements that found the right number of records/values in ColumnA this would ensure that the correct number of array values were added together. Everything in the code is functional however, I plan to have hundreds of values in my table and many more columns so I would have to use hundreds and hundreds of if then statements. If anyone is out there who knows an easier and more efficient way of calculating the averages of values in a table I would greatly appreciate some help. I am sure this is a common problem but unfortunately I have not seen any tutorials or forum topics devoted to it.
'Find the number of values
Dim iRecordCount
iRecordCount = 0
DO WHILE NOT rsVariable.EOF
iRecordCount = iRecordCount + 1
rsVariable.MoveNext
Loop
'Find and hold the values in CategoryA
rsVariable.MoveFirst
DIM ARR1()
FOR I = 1 to iRecordCount
Redim preserve ARR1(I)
ARR1(I) = rsVariable("CategoryA")
rsVariable.MoveNext
NEXT
'Depending on the number of records add that number of records together using the values held in the array
if iRecordCount = 2 then
total2 = int(ARR1(1)) + int(ARR1(2))
response.write int(total2)/int(iRecordCount)
else
end if
if iRecordCount = 3 then
total3 = int(ARR1(1)) + int(ARR1(2)) + int(ARR1(3))
response.write int(total3)/int(iRecordCount)
else
end if
