Trying to create a function to calculate a grade

Serendipityww

Registered User.
Local time
Today, 13:24
Joined
Sep 6, 2000
Messages
18
Scenario: The class has 3 technique checks. If the student makes an A (11) or A- (10) on Tech1 and Tech2, then he won't take Tech3. If the student doesn't make an A or A- on each of the first two then he will take the third technique check.
I need a function to use on a form (actually public as I will also use it with other forms) that will average the two highest technique grades and then multiply by a percent which varies with the course. I have tried an If statement, a case statement, and a bubble sort but can't get it to work.
Also, some courses have two technique checks and others have three or four. That is why I was trying to do a bubble sort. Can I do all with one function or do I need to make a separate function depending on how many technique checks there are?
My VB skills are intermediate. Thanks so much for your help. This forum has saved me from many headaches.
 
Hi Serendipityww,
Here is a function that will do what you're asking. Paste the code below into a new module. It accepts a variable number of fields and/or static values. Here is an example of the syntax used to call it:

AvgGrade([Factor],[Tech1],[Tech2],[Tech3])

The Factor should be a double between 0 and 1 representing the percent to multiply the average by. If you have any questions feel free to post them here or email me. Good luck!

Code:
Function AvgGrade(ByVal Factor As Double, ParamArray Values()) As Double
Dim x As Integer, int1 As Double, int2 As Double, chk As Integer
x = UBound(Values())
For x = 0 To x
    If Values(x) > int1 Then int1 = Values(x): chk = x
Next x
x = UBound(Values())
For x = 0 To x
    If x <> chk And Values(x) > int2 Then int2 = Values(x)
Next x
AvgGrade = ((int1 + int2) / 2) * Factor
End Function

~Abby
 
Thanks. I will try it. By calling it, you mean put an = in front of AvgGrade([Factor],[Tech1],[Tech2],[Tech3]) and put it as the control source for the control that gets the result?
 
Exactly. Once you create the function you can use it the same way you would any other function, as a control's source (with the = in front), in subroutines, in query calculations, ect...

~Abby
 

Users who are viewing this thread

Back
Top Bottom