help with my visual basic code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I had to make a grading program for in VB2010 and it turned out great. except now my professor had us take some of the code (how it computes the grade) and turn those methods into classes. I had it done or so i thought and had to redo the classes. now when i enter in a score all i get back is an F no matter what i do. heres the code...any help would be great!!!Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
#Region "CONSTANTS AND VARIABLES"
Const mdecMAX_QUIZ_POINTS As Decimal = 5
Const mdecMAX_TEST_POINTS As Decimal = 50
Const mdecMAX_FINAL_POINTS As Decimal = 100
Dim mIntNumberOfScoresEntered As Integer
#End Region
#Region "BOSS MODULE: CALCULATE REGION"
*************************************************************************************************************************************************
CLICKED BUTTON RUNS PROGRAM
*************************************************************************************************************************************************
- Clicking the button calls on the subprocedures in program
******************************************************************************************************

Private Sub btnCalculateGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateGrade.Click
Dim blnErrorFlag As Boolean = False
Dim decNumberCorrect As Decimal
Call ValidateData(blnErrorFlag, decNumberCorrect)
If blnErrorFlag = True Then
Exit Sub
End If
Call CountScoresEntered()
If radNoPlusMinus.Checked = True Then
Call GradesWithoutPlusAndMinus(decNumberCorrect)
Else
Call GradesWithPlusAndMinus(decNumberCorrect)
End If
End Sub
#End Region
#Region "VALIDATE DATA"
*************************************************************************************************************************************************
ERROR FLAG MESSAGE
*************************************************************************************************************************************************
- If user doe snot provide all necesary information then error messages pops up stating so
*************************************************************************************************************************************************
Sub ValidateData(ByRef blnErrorFlag As Boolean, ByRef decNumberCorrect As Decimal)
Try
decNumberCorrect = CInt(txtNumberCorrect.Text)
Catch UserError As InvalidCastException
MessageBox.Show("You must enter a numeric value.")
blnErrorFlag = True
End Try
If radQuiz.Checked = True And decNumberCorrect > 5 Then
MessageBox.Show("Points must not exceed 5.")
blnErrorFlag = True
End If
If radTest.Checked = True And decNumberCorrect > 50 Then
MessageBox.Show("Points must not exceed 50.")
blnErrorFlag = True
End If
If radFinal.Checked = True And decNumberCorrect > 100 Then
MessageBox.Show("Points must not exceed 100.")
blnErrorFlag = True
End If
End Sub
#End Region
#Region "BOSS MODULE: GRADES WITHOUT + -"
*************************************************************************************************************************************************
GRADES WITHOUT PLUS/MINUS
*************************************************************************************************************************************************
- Calls upon grade equations and shows results without a plus (+) or minus (-)
*************************************************************************************************************************************************
Private Sub GradesWithoutPlusAndMinus(ByVal decNumberCorrect As Decimal)
Dim decPenalty As Decimal
Dim mdecPercentageScore As Decimal
Dim mstrLetterGrade As String = Nothing
decPenalty = CalculatePenalty() use this statement when using a function to calculate penalty
Call CalculatePercentageScore(decNumberCorrect, decPenalty, mdecPercentageScore)
Call CalculateLetterGradeWithOutPlusAndMinus(mdecPercentageScore, mstrLetterGrade)
Call DisplayPercentageAndGradeAndCount(mdecPercentageScore, mstrLetterGrade)
End Sub
#End Region
#Region "BOSS MODULE: GRADES WITH + -"
*************************************************************************************************************************************************
GRADES WITH PLUS/MINUS
*************************************************************************************************************************************************
- Calls upon grade equations and shows results with a plus (+) or minus (-)
*************************************************************************************************************************************************
Private Sub GradesWithPlusAndMinus(ByVal decNumberCorrect As Decimal)
Dim decPenalty As Decimal
Dim mdecPercentageScore As Decimal
Dim mstrLetterGrade As String = Nothing
decPenalty = CalculatePenalty() use this statement when using a function to calculate penalty
Call CalculatePercentageScore(decNumberCorrect, decPenalty, mdecPercentageScore)
Call CalculateLetterGradeWithPlusAndMinus(mdecPercentageScore, mstrLetterGrade)
Call DisplayPercentageAndGradeAndCount(mdecPercentageScore, mstrLetterGrade)
End Sub
#End Region
#Region "CALCULATE PERCENTAGE SCORE"
*************************************************************************************************************************************************
CALCULATES GRADE PERCENTAGE
*************************************************************************************************************************************************
- based on the radio button selected takes number correct on quiz, test, or final after deducted penalties and outputs the percentage
*************************************************************************************************************************************************
Private Sub CalculatePercentageScore(ByVal decNumberCorrect As Decimal, ByVal decPenalty As Decimal, ByRef mdecPercentageScore As Decimal)
If radQuiz.Checked Then
mdecPercentageScore = (decNumberCorrect - decPenalty) / mdecMAX_QUIZ_POINTS
End If
If radTest.Checked Then
mdecPercentageScore = (decNumberCorrect - decPenalty) / mdecMAX_TEST_POINTS
End If
If radFinal.Checked Then
mdecPercentageScore = (decNumberCorrect - decPenalty) / mdecMAX_FINAL_POINTS
End If
End Sub
#End Region
#Region "CALCULATE PENALTY"
*************************************************************************************************************************************************
CALCULATES PENALTY
*************************************************************************************************************************************************
- Takes user inputted penalties and subtracts them total correct on quiz, test, or final
*************************************************************************************************************************************************
Private Function CalculatePenalty() As Decimal
Dim decPenalty As Decimal

If chkIncorrectID.Checked Then
decPenalty = decPenalty + 2
End If
If chkIncorrectScantron.Checked Then
decPenalty = decPenalty + 5
End If
If chkNoName.Checked Then
decPenalty = decPenalty + 2
End If
Return decPenalty
End Function
#End Region
#Region "CALCULATE LETTER GRADE WITH + -"
Sub CalculateLetterGradeWithPlusAndMinus(ByVal mdecPercentageScore As Decimal, ByRef strLetterGrade As String)
Dim objLetterGradeWithPlusMinus As New clsLetterGradeWithPlusMinus
objLetterGradeWithPlusMinus.PercentageScore = mdecPercentageScore
strLetterGrade = objLetterGradeWithPlusMinus.ComputeLetterGrade
End Sub
#End Region
#Region "CALCULATE LETTER GRADE W/O + -"
Sub CalculateLetterGradeWithOutPlusAndMinus(ByVal decPercentageScore As Decimal, ByRef strLetterGrade As String)
Dim objLetterGradeWOPlusMinus As New clsLetterGradeWOPlusMinus
objLetterGradeWOPlusMinus.PercentageScore = decPercentageScore
strLetterGrade = objLetterGradeWOPlusMinus.ComputeLetterGrade
End Sub
#End Region
#Region "DISPLAY PERCENTAGE, GRADE, COUNT"
*************************************************************************************************************************************************
DISPLAYS PERCENTAGE AND GRADE
*************************************************************************************************************************************************
- Converts percentage score from decimal to full percentage and displays it
- Displays the letter grade
*************************************************************************************************************************************************
Private Sub DisplayPercentageAndGradeAndCount(ByVal mdecPercentageScore As Decimal, ByRef strLetterGrade As String)
lblPercentage.Text = CStr(CInt(mdecPercentageScore * 100)) + "%"
lblLetterGrade.Text = strLetterGrade
lblScoresEntered.Text = CStr(mIntNumberOfScoresEntered)
If mdecPercentageScore < 0.7 Then
lblLetterGrade.ForeColor = Color.Red
Else
lblLetterGrade.ForeColor = Color.Black
End If
End Sub
*************************************************************************************************************************************************
TOTAL NUMBER OF SCORES
*************************************************************************************************************************************************
- Counts how many times a score has been entered
*************************************************************************************************************************************************
Private Sub CountScoresEntered()
mIntNumberOfScoresEntered = mIntNumberOfScoresEntered + 1
End Sub
#End Region
#Region "CLEAR RADIO BUTTONS"
*************************************************************************************************************************************************
STARTS WITH RADIO CHECKED
*************************************************************************************************************************************************
- Starts program with no plus or minus grade
*************************************************************************************************************************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
radNoPlusMinus.Checked = True
End Sub
#End Region
#Region "CLEAR SETTINGS"
*************************************************************************************************************************************************
CLEARS SELECTIONS UPON CLICKING
*************************************************************************************************************************************************
- Clears the letter grade, percentage, scores entered labels and the 3 penalty check boxes when you click the number correct text box
*************************************************************************************************************************************************
Private Sub txtNumberCorrect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNumberCorrect.Click
lblLetterGrade.Text = ""
lblPercentage.Text = ""
lblScoresEntered.Text = ""
chkIncorrectID.Checked = False
chkIncorrectScantron.Checked = False
chkNoName.Checked = False
End Sub
#End Region
#Region "EXIT PROGRAM"
*************************************************************************************************************************************************
CLOSES APPLICATION
*************************************************************************************************************************************************
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
#End Region
End Class

Option Strict On
Public Class clsLetterGradeWOPlusMinus
#Region "Constants and Variable Declarations"
Private mdecPercentageScore As Decimal
Private mstrLetterGrade As String
#End Region
#Region "Properties"
*************************************************************************************************************************************************
SETS PROPERTIES
*************************************************************************************************************************************************
- Sets the value of the percentage score
*************************************************************************************************************************************************
Public Property PercentageScore As Decimal
Get
Return mdecPercentageScore
End Get
Set(ByVal Value As Decimal)
mdecPercentageScore = Value
End Set
End Property
Public ReadOnly Property A_Cutoff As Decimal
Get
Return 90
End Get
End Property
Public ReadOnly Property B_Cutoff As Decimal
Get
Return 80
End Get
End Property
Public ReadOnly Property C_Cutoff As Decimal
Get
Return 70
End Get
End Property
Public ReadOnly Property D_Cutoff As Decimal
Get
Return 60
End Get
End Property
#End Region
#Region "Methods"
*************************************************************************************************************************************************
DETERMINES NORMAL LETTER GRADE
*************************************************************************************************************************************************
- Based on percentage score determines what standard letter grade to give
*************************************************************************************************************************************************
Public Function ComputeLetterGrade() As String
If mdecPercentageScore >= A_Cutoff Then
mstrLetterGrade = "A"
ElseIf mdecPercentageScore >= B_Cutoff Then
mstrLetterGrade = "B"
ElseIf mdecPercentageScore >= C_Cutoff Then
mstrLetterGrade = "C"
ElseIf mdecPercentageScore >= D_Cutoff Then
mstrLetterGrade = "D"
ElseIf mdecPercentageScore < 60 Then
mstrLetterGrade = "F"
End If
Return mstrLetterGrade

End Function
#End Region
End Class

Option Strict On
Public Class clsLetterGradeWithPlusMinus
#Region "Constants and Variable Declarations"
Private mdecPercentageScore As Decimal
Private mstrLetterGrade As String
#End Region
#Region "Properties"
*************************************************************************************************************************************************
SETS PROPERTIES
*************************************************************************************************************************************************
- Sets the value of the percentage score
*************************************************************************************************************************************************
Public Property PercentageScore As Decimal
Get
Return mdecPercentageScore
End Get
Set(ByVal Value As Decimal)
mdecPercentageScore = Value
End Set
End Property
Public ReadOnly Property A_P_Cutoff As Decimal
Get
Return 97
End Get
End Property
Public ReadOnly Property A_Cutoff As Decimal
Get
Return 93
End Get
End Property
Public ReadOnly Property A_M_Cutoff As Decimal
Get
Return 90
End Get
End Property
Public ReadOnly Property B_P_Cutoff As Decimal
Get
Return 87
End Get
End Property
Public ReadOnly Property B_Cutoff As Decimal
Get
Return 83
End Get
End Property
Public ReadOnly Property B_M_Cutoff As Decimal
Get
Return 80
End Get
End Property
Public ReadOnly Property C_P_Cutoff As Decimal
Get
Return 77
End Get
End Property
Public ReadOnly Property C_Cutoff As Decimal
Get
Return 73
End Get
End Property
Public ReadOnly Property C_M_Cutoff As Decimal
Get
Return 70
End Get
End Property
Public ReadOnly Property D_P_Cutoff As Decimal
Get
Return 67
End Get
End Property
Public ReadOnly Property D_Cutoff As Decimal
Get
Return 63
End Get
End Property
Public ReadOnly Property D_M_Cutoff As Decimal
Get
Return 60
End Get
End Property
#End Region
#Region "Methods"
*************************************************************************************************************************************************
DETERMINES LETTER GRADE
*************************************************************************************************************************************************
- Based on percentage score determines what letter grade to give
*************************************************************************************************************************************************
Public Function ComputeLetterGrade() As String
If mdecPercentageScore >= A_P_Cutoff Then
mstrLetterGrade = "A+"
ElseIf mdecPercentageScore >= A_Cutoff Then
mstrLetterGrade = "A"
ElseIf mdecPercentageScore >= A_M_Cutoff Then
mstrLetterGrade = "A-"
ElseIf mdecPercentageScore >= B_P_Cutoff Then
mstrLetterGrade = "B+"
ElseIf mdecPercentageScore >= B_Cutoff Then
mstrLetterGrade = "B"
ElseIf mdecPercentageScore >= B_M_Cutoff Then
mstrLetterGrade = "B-"
ElseIf mdecPercentageScore >= C_P_Cutoff Then
mstrLetterGrade = "C+"
ElseIf mdecPercentageScore >= C_Cutoff Then
mstrLetterGrade = "C"
ElseIf mdecPercentageScore >= C_M_Cutoff Then
mstrLetterGrade = "C-"
ElseIf mdecPercentageScore >= D_P_Cutoff Then
mstrLetterGrade = "D+"
ElseIf mdecPercentageScore >= D_Cutoff Then
mstrLetterGrade = "D"
ElseIf mdecPercentageScore >= D_M_Cutoff Then
mstrLetterGrade = "D-"
ElseIf mdecPercentageScore < 60 Then
mstrLetterGrade = "F"
End If
Return mstrLetterGrade
End Function
#End Region

End Class

View the full article
 
Back
Top