Solved

calculating marks added on a form immediately

Posted on 2002-03-05
11
185 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
11 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
homework?
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
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
Comment Utility
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
 
LVL 7

Expert Comment

by:Joe_Griffith
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:Joe_Griffith
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks very much daniellhy
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now