Solved

calculating marks added on a form immediately

Posted on 2002-03-05
11
191 Views
Last Modified: 2010-05-02
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.
 
0
Comment
Question by:Bush21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6841234
homework?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6841303
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
 
LVL 15

Expert Comment

by:ameba
ID: 6841435
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 6842452
You need to be a little more specific with your question.  Which part of the program are you having a problem with?
0
 

Author Comment

by:Bush21
ID: 6843661
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
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 6847236
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
 

Author Comment

by:Bush21
ID: 6849793
Joe griffin this is exacltly the problem:
trouble averaging the exam scores?
problems displaying the data?

0
 
LVL 1

Accepted Solution

by:
daniellyh earned 65 total points
ID: 6859464
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
 

Author Comment

by:Bush21
ID: 6860005
thanks very much daniellhy
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7591783
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
 

Expert Comment

by:modulo
ID: 7624099
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 9 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question