How do I find the average value from a column of v

Results 1 to 2 of 2

Thread: How do I find the average value from a column of v

  1. #1
    Join Date
    Dec 1969

    Default How do I find the average value from a column of v

    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.<BR><BR>&#039;Find the number of values<BR>Dim iRecordCount<BR>iRecordCount = 0<BR>DO WHILE NOT rsVariable.EOF<BR>iRecordCount = iRecordCount + 1<BR>rsVariable.MoveNext<BR>Loop<BR><BR>&#039;Fin d and hold the values in CategoryA<BR>rsVariable.MoveFirst<BR>DIM ARR1()<BR>FOR I = 1 to iRecordCount<BR>Redim preserve ARR1(I)<BR>ARR1(I) = rsVariable("CategoryA")<BR>rsVariable.MoveNext<BR> NEXT<BR><BR>&#039;Depending on the number of records add that number of records together using the values held in the array <BR>if iRecordCount = 2 then<BR>total2 = int(ARR1(1)) + int(ARR1(2))<BR>response.write int(total2)/int(iRecordCount)<BR>else<BR>end if<BR><BR>if iRecordCount = 3 then<BR>total3 = int(ARR1(1)) + int(ARR1(2)) + int(ARR1(3))<BR>response.write int(total3)/int(iRecordCount)<BR>else<BR>end if<BR>

  2. #2
    Join Date
    Dec 1969

    Default ** crosspost **


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts