calculating marks added on a form immediately

I have created a form using VB in which a student enters his details and the marks he got on the 8 different exams he worte.  I want  a code in which the marks the students enters are calculated and the average is displayed on the form on a text box and when the student presses the submit button, that average should be stored in the table also together with the average.
Below are the fields in the form;
-Name
-Surname
-ID nummber
-Exams 1 to 8 Fields(The student wrote exams)
-Average (this is the field that should display the average automatically)
Then there is the cancel and the submit button

I have linked this form to the table already.
 
Bush21Asked:
Who is Participating?
 
daniellyhConnect With a Mentor Commented:
may b u can try this simple codes:

'create 9 text boxes in a form, named text1 - text9
'text9 is the average
Dim x As Control
Dim total, avg As Double

Private Sub Form_Load()
On Error Resume Next
For Each x In Controls
    If TypeOf x Is TextBox Then
        x.Text = ""
    End If
   
Next
End Sub

Private Sub Text1_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text2_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text3_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text4_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text5_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text6_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text7_Change()
On Error Resume Next
    calc
End Sub

Private Sub Text8_Change()
On Error Resume Next
    calc
End Sub

Function calc()
    total = (Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) _
    + Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text) + Val(Text8.Text))
    If IsNumeric(total) Then
        avg = total / 8
        Text9.Text = avg
    End If
End Function

good luck
0
 
Éric MoreauSenior .Net ConsultantCommented:
homework?
0
 
Arthur_WoodCommented:
You should NOT store the Average (or ANY calcualted value, fir that matter) in your database.  You can easily COMPUTE the value, when the data is to be displayed, either with a Query, or in a Report, or on a form.  Storing Calcualted fields is a MAJOR violation of standard Database design Normalization rules.

Arthur Wood
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
amebaCommented:
You should sum and count all valid (non-empty) values.
     avg = sum / count
The best is to use Change event of the textbox.
To check if valid value is in textbox, use IsNumeric function.

>You should NOT store the Average

That is correct, but sometimes denormalization can be used for performance reasons.
http://www.biochem.ucl.ac.uk/~shepherd/mmb/lect03/section02.html
0
 
Joe_GriffithCommented:
You need to be a little more specific with your question.  Which part of the program are you having a problem with?
0
 
Bush21Author Commented:
Joe Griffith I'm having a problem with the whole part of the question, just try what to get from it and i will award the marke to you.
0
 
Joe_GriffithCommented:
I'm not concerned about the points.  To get good answers, however, you have to ask good questions.  Your question is so broad that it is difficult to tell what you want.

Are you having trouble averaging the exam scores?
Are you having problems displaying the data?
Are you having problems reading or writing to a database?

0
 
Bush21Author Commented:
Joe griffin this is exacltly the problem:
trouble averaging the exam scores?
problems displaying the data?

0
 
Bush21Author Commented:
thanks very much daniellhy
0
 
DanRollinsCommented:
Hi Bush21,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept daniellyh's comment(s) as an answer.

Bush21, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
moduloCommented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.