Solved Calculating Percentage and Comparing it with Given Criteria to Determine Grades (1 Viewer)

Pac-Man

Active member
Local time
Tomorrow, 00:05
Joined
Apr 14, 2020
Messages
408
Hello,

I'm trying to use following code to calculate percentage and then calculated percentage will be compared with a grading criteria to determine grades of students.

Code:
Dim lngPercentage As Single
lngPercentage = (cMarksObtaind * 100) / cMaximumMarks

Problem is, if a percentage is 39.5, it is compared with criteria which is if lngPercentage is less than 40 then it should assign grade F but percentage is rounded off to 40 and it assign grade pass and same is for other grades. I want the calculated percentage value to have one digit after the decimal sign but it behaving like an integer. How can I resolve the issue.

Best Regards,
Abdullah
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:05
Joined
May 7, 2009
Messages
19,169
create a Mark table (with possible fields)

MinValue (double), eg: 0
MaxValue (double) eg: 40
Grade (short text) eg: F

fill the table with minValue, maxValue (range) and the correspoding grade.
you can use Query or DLookup() to get the Grade:

DLookup("Grade","MarkTable", [textbox] & " Between [minValue] And [maxValue]")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:05
Joined
May 7, 2009
Messages
19,169
Dim lngPercentage As Single
lngPercentage = Fix(cMarksObtaind / cMaximumMarks * 100) / 100
 

Pac-Man

Active member
Local time
Tomorrow, 00:05
Joined
Apr 14, 2020
Messages
408
create a Mark table (with possible fields)

MinValue (double), eg: 0
MaxValue (double) eg: 40
Grade (short text) eg: F

fill the table with minValue, maxValue (range) and the correspoding grade.
you can use Query or DLookup() to get the Grade:

DLookup("Grade","MarkTable", [textbox] & " Between [minValue] And [maxValue]")
Dim lngPercentage As Single
lngPercentage = Fix(cMarksObtaind / cMaximumMarks * 100) / 100
Thanks @arnelgp for reply. I tried second code but it stored lngPercentage as 0.4 (instead of 0.396) for input marks 39.6 out of 100. I prefer to use vba instead of query or dlookup as I have written the whole procedure and have to rewrite again to change for min max values. Is it not possible to have VBA not round off the calculated value or round off to only certain digits instead of rounding off to integer?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:05
Joined
May 7, 2009
Messages
19,169
you can also Cast the values as decimal:

lngPercentage = (CDec(cMarksObtaind) * 100) / CDec(cMaximumMarks)
 

Pac-Man

Active member
Local time
Tomorrow, 00:05
Joined
Apr 14, 2020
Messages
408
you can also Cast the values as decimal:

lngPercentage = (CDec(cMarksObtaind) * 100) / CDec(cMaximumMarks)
Thanks it worked. I used incorrectly before. Thanks for the assistance.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 19:05
Joined
Sep 12, 2006
Messages
15,614
You might be able to use a partition query to split the data into the grade groupings. It's very powerful but not often used.
 

Pac-Man

Active member
Local time
Tomorrow, 00:05
Joined
Apr 14, 2020
Messages
408
You might be able to use a partition query to split the data into the grade groupings. It's very powerful but not often used.
Never heard of partition query before. I'll check it. Thanks for suggestion.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:05
Joined
Feb 19, 2002
Messages
42,971
Create a table with three fields
LetterGrade (2 character, primary key)
From (low bound of numeric range)
To (high bound of numeric range.

Using two characters allows for + and - gradients.

Then use a query to find the appropriate letter grade.

Select LetterGrade From tblLetterGrade where Forms!myform!txtNumericGrade > = From AND Forms!myform!txtNumericGrade <= To;
 

Pac-Man

Active member
Local time
Tomorrow, 00:05
Joined
Apr 14, 2020
Messages
408
Create a table with three fields
LetterGrade (2 character, primary key)
From (low bound of numeric range)
To (high bound of numeric range.

Using two characters allows for + and - gradients.

Then use a query to find the appropriate letter grade.

Select LetterGrade From tblLetterGrade where Forms!myform!txtNumericGrade > = From AND Forms!myform!txtNumericGrade <= To;
Thanks a lot @Pat Hartman. I have used a table to store the grades but method suggested by you and @arnelgp (i.e. table having from and to bounds for a grade and find the grade using query) gave me another method by which I could handle grading of students. I'll check this too. Stay safe and healthy.
 

Users who are viewing this thread

Top Bottom