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
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?
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
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.
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.
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
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
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?
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.
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
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.