Hi all,
I am trying to get the average of student marks from the database into texboxes on the form(via the datagriid).
I have four fields
I use the usual method for accessing the database and displaying the data into a datagridview.
I then use the following loop to get the data from DB then average the marks.This code will get the average of the last three marks into a textbox
Dim sum1 As double
Dim a As single
For a = 0 to 2
sum +=
TextBox4.Text = sum/3
This works fine for a student with three marks.
But I want to look at the average for four five six and seven marks and place each one in a seperate TBox.So I just duplicated the above code and changed the varaibles in each one to correspond to the increments.So for example the loop for 5 grades would be this
Dim sum1 As double
Dim b  As single
For b = 0 to 4
sum +=
TextBox4.Text = sum/5
So these loops examine the column in the DGV,stop at the rquired amount and then work out an average.
The problem arises when a student may only have 3 grades,the loop however will go up to lets say7 and instead of just ignoring the empty spaces it is treating them as zeros
so imagine the student has 20,45,66 the average would be 43.6,which is correct
But the seven loop is in the DGT looks at it like this,20,45,66,0,0,0,0, and comes up with the average of 18.5.which of course is wrong.

I hope I have explained everything clearly,I am not too sure if I am even doing this right(I am from an Excel baxkground branching out into vb.net) .
Ant suggestions much appreciated.
Kind Regards