Results 1 to 21 of 21

Thread: [RESOLVED] Grade Calculator

  1. #1

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Resolved [RESOLVED] Grade Calculator

    I'm currently working on a project for school that allows the user to calculate the lowest grade they can get on their final exam (NeededPercent(1 To 8) as Integer) and still recieve their desired score(DesiredScore(1 To 8) as Integer).

    What the user does is enter their first quarter grade (FirstQuarter(1 To 8) as Integer), second quarter grade(SecondQuarter((1 To 8) as Integer) and desired semester score. The program then uses the equation

    ((1stQuarter*.4)+(2ndQuarter*.4))+(FinalExamScore*.2) = SemesterGrade

    to figure out what they need on their final.

    My question was that I get an error when I try to use a textbox to get the user to input the value of their quarter grades and desired final score. I think the problem is that I'm putting numbers in a text box; is this the likely problem?

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: Grade Calculator

    There will be problems if you are adding non-numeric characters in the textbox, eg. 50%.

    You'll have to make sure you remove all non-numeric chars from the textboxes before calculating.

    Code:
    '-- Function to Remove non numeric chars from value
    Function NumericOnly(ByVal text As String) As Single
    Dim i As Integer
    Dim n As String
    
      For i = 1 To Len(text)
        If IsNumeric(Mid(text, i, 1)) Then n = n & Mid(text, i, 1)
        If Mid(text, i, 1) = "." Then n = n & "." '-- Include decimals
      Next
    
      NumericOnly = CSng(n)
    End Function
    
    '-- Now formula changes
    ((NumericOnly(1stQuarter)*.4)+(NumericOnly(2ndQuarter)*.4))+(NumericOnly(FinalExamScore)*.2) = SemesterGrade

    r0ach™
    Don't forget to rate the post

  3. #3

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    My problem occurs before the program can even load, so I'm pretty sure it doesn't have to do with that.

    I uploaded the file, if that would be of any help.


    http://www.vbforums.com/attachment.p...1&d=1180814962
    Attached Files Attached Files

  4. #4

  5. #5

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    Thanks for that. How would I go about compiling it?

  6. #6

  7. #7
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Grade Calculator

    Being British I have no idea what your trying to do but the problem seems to be that you have said that each section(?) of the array is an integer. Then in the Form_Load procedure you have said that each is "". Move this to the command button and I think it should work.

  8. #8

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    Quote Originally Posted by 03myersd
    Being British I have no idea what your trying to do but the problem seems to be that you have said that each section(?) of the array is an integer. Then in the Form_Load procedure you have said that each is "". Move this to the command button and I think it should work.
    Let me buy you a cup of tea sometime, because it worked.

  9. #9
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Grade Calculator

    I don't drink tea but thanks for the offer.

    Think that makes this thread resolved then? Twice over! Lol.

  10. #10

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    One last question, this one math related.

    If I were trying to figure out what score the user would need to get on their final to achieve a desired score (also user-inputted), what equation would I use?

    This is the equation to figure out a semester grade
    ((1stQuarter*.4)+(2ndQuarter*.4))+(FinalExamScore*.2) = SemesterGrade

  11. #11
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Grade Calculator

    As in:

    FinalExamScore = -(((1stQuarter*.4)-(2ndQuarter*.4)) + SemesterGrade) * 5

    Once again I aint sure what you need so this is only a guess.

  12. #12

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    vb Code:
    1. Sub Calculation()
    2.  
    3. Dim x As Long
    4. For x = 1 To UBound(DesiredGrade)
    5.     If DesiredGrade(x) = "A" Or "a" Or "A+" Or "A-" Or "a+" Or "a-" Then
    6.         GradeDesired(x) = 90
    7.     ElseIf DesiredGrade(x) = "B" Or "b" Or "B+" Or "B-" Or "b+" Or "b-" Then
    8.         GradeDesired(x) = 80
    9.     ElseIf DesiredGrade(x) = "C" Or "c" Or "C+" Or "C-" Or "c+" Or "c-" Then
    10.         GradeDesired(x) = 70
    11.     ElseIf DesiredGrade(x) = "D" Or "d" Or "D+" Or "D-" Or "d+" Or "d-" Then
    12.         GradeDesired(x) = 65
    13.     Else
    14.         GradeDesired(x) = 64
    15.     End If
    16. Next x
    17.    
    18.  
    19.  
    20. Dim i As Long
    21. For i = 1 To UBound(DesiredScore)
    22.   NeededPercent(i) = -(((FirstQuarter(i) * 0.4) - (SecondQuarter(i) * 0.4)) [B]+[/B] GradeDesired) * 5
    23. Next i
    I get the error "type mismatch" and get the boldened code selected (just the addition sign). Does anyone know what's wrong?

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Grade Calculator

    Assuming that the 1st and 2nd quarter values are known and that you want to know what score you need on the final exam to get a certain SemesterGrade (assume 80) then



    FinalExamScore = 5 * (80 - (1stQuarter *.4) + (2ndQuarter *.4))

    so if you got 90 in the 1st qtr and 70 in the 2nd you'd need 80 on the final exam

    FinalExamScore = 5 * (80 - (80 *.4) + (70 *.4))
    FinalExamScore = 5 * (80 - (36) + (28))
    FinalExamScore = 5 * (80 - 64)
    FinalExamScore = 5 * (16)
    FinalExamScore = 80

  14. #14

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    Huh, I think there may be something fundamentally flawed with my code. I keep getting the same error for a different section now...


    Option Explicit
    Dim FirstQuarter(1 To 8) As Integer
    Dim SecondQuarter(1 To 8) As Integer
    Dim DesiredGrade(1 To 8) As String
    Dim NeededPercent(1 To 8) As Integer
    Dim DesiredScore(1 To 8) As Integer
    Dim GradeDesired(1 To 8) As Integer

    Sub Calculation()

    Dim x As Long
    For x = 1 To UBound(DesiredGrade)
    If DesiredGrade(x) = "A" Or "a" Or "A+" Or "A-" Or "a+" Or "a-" Then
    GradeDesired(x) = 90
    ElseIf DesiredGrade(x) = "B" Or "b" Or "B+" Or "B-" Or "b+" Or "b-" Then
    GradeDesired(x) = 80
    ElseIf DesiredGrade(x) = "C" Or "c" Or "C+" Or "C-" Or "c+" Or "c-" Then
    GradeDesired(x) = 70
    ElseIf DesiredGrade(x) = "D" Or "d" Or "D+" Or "D-" Or "d+" Or "d-" Then
    GradeDesired(x) = 65
    Else
    GradeDesired(x) = 64
    End If
    Next x


    I keep getting the type-mismatch during

    If DesiredGrade(x) = "A" Or "a" Or "A+" Or "A-" Or "a+" Or "a-" Then

    section of the code. Does anyone know what I keep doing wrong to cause this error?

  15. #15

  16. #16

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    Desired Grade is put in by the user (which is where I get the "A" or "a" or etc. part of the code) which then gets translated to the lowest percentage that would still be the grade put in by the user, and stored in a seperate variable as an integer.

    I just changed my code so x = 1 to begin.

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Grade Calculator

    You missed the IF statements Marty

    Frances Farmer, it is not valid to do this:
    Code:
     If DesiredGrade(x) = "A" Or "a" Or "A+" Or "A-" Or "a+" Or "a-" Then
    ..instead you need to use the variable between each Or, eg:
    Code:
     If DesiredGrade(x) = "A" Or DesiredGrade(x) = "a" Or DesiredGrade(x) = "A+" Or DesiredGrade(x) = "A-" Or DesiredGrade(x) = "a+" Or DesiredGrade(x) = "a-" Then
    ..or better still, use a Select Case instead of all the If statements, eg:
    Code:
     Select Case DesiredGrade(x) 
      Case "A", "a", "A+", "A-", "a+", "a-"
        GradeDesired(x) = 90
      Case "B", "b" ...
    ...
      Case Else
        GradeDesired(x) = 64
      End Select

  18. #18
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Grade Calculator

    He's not the only one who did....

    Edit: Do you happen to have any test data for this program? I am kinda caught up in it now. lol.
    Last edited by 03myersd; Jun 4th, 2007 at 12:44 PM.

  19. #19
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Grade Calculator

    Quote Originally Posted by si_the_geek
    You missed the IF statements Marty
    I sure did.

    This would also improve things

    Code:
     Select Case UCase(DesiredGrade(x)) 
      Case "A", "A+", "A"
        GradeDesired(x) = 90
      Case "B" ...
    ...
      Case Else
        GradeDesired(x) = 64
      End Select
    or even

    Code:
     Select Case Left$(UCase(DesiredGrade(x)), 1) 
      Case "A"
        GradeDesired(x) = 90
      Case "B" ...
    ...
      Case Else
        GradeDesired(x) = 64
      End Select

  20. #20

    Thread Starter
    Member Frances Farmer's Avatar
    Join Date
    Apr 2007
    Location
    Chicago area
    Posts
    32

    Re: Grade Calculator

    This program is working quite well now. Thanks to everyone for their help!

  21. #21
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Grade Calculator

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width