The Worksheet named Grades contains a place for students to record the grades they have received in their classes. Students put the number of each letter grade received in the B column. (For example, the worksheet currently shows that the student has taken 9 classes and made five As, one B, one C, one D, and one F as grades. You need to write a program that reads the grades from the worksheet and uses a function to calculate the student’s GPA. For this problem you can assume that all classes are worth the same number of credit hours. The function should send back the GPA to the calling procedure. The procedure will then put up a message box that gives the student their GPA and a message about their GPA, all in one message box. The message should be “You qualify for an internship” if the student has a GPA of at least 3.0. It should be “You’re in the danger zone” if the GPA is between 2.0 and 3.0. And it should be “You are on probation.” if the GPA 2.0 or lower. The message box below is an example of what should be shown to the user. Do not worry about the formatting of the GPA, if yours has lots of decimal places, that is OK.
Write VBA CODE FOR THE FOLLOWING PROBLEM
Problem:
- The Worksheet named Grades contains a place for students to record the grades they have received in their classes. Students put the number of each letter grade received in the B column. (For example, the worksheet currently shows that the student has taken 9 classes and made five As, one B, one C, one D, and one F as grades. You need to write a program that reads the grades from the worksheet and uses a function to calculate the student’s GPA. For this problem you can assume that all classes are worth the same number of credit hours. The function should send back the GPA to the calling procedure. The procedure will then put up a message box that gives the student their GPA and a message about their GPA, all in one message box. The message should be “You qualify for an internship” if the student has a GPA of at least 3.0. It should be “You’re in the danger zone” if the GPA is between 2.0 and 3.0. And it should be “You are on probation.” if the GPA 2.0 or lower. The message box below is an example of what should be shown to the user. Do not worry about the formatting of the GPA, if yours has lots of decimal places, that is OK.
Sub showValue()
Dim arr(9)
For i = 0 To 8 Step 1
arr(i) = Range("B" & (i + 2))
Next
Dim gpa As Double
gpa = 0
For i = 0 To 8 Step 1
If arr(i) = "A" Then
gpa = gpa + 10
ElseIf arr(i) = "B" Then
gpa = gpa + 9
ElseIf arr(i) = "C" Then
gpa = gpa + 8
ElseIf arr(i) = "D" Then
gpa = gpa + 7
ElseIf arr(i) = "F" Then
gpa = gpa + 5
End If
Next
If gpa > 3 Then
MsgBox "You qualify for an internship " & "GPA: " & gpa
ElseIf gpa < 3 And gpa > 2 Then
MsgBox "You’re in the danger zone " & "GPA: " & gpa
ElseIf gpa < 2 Then
MsgBox "GPA: " + gpa + "You are on probation. " & "GPA: " & gpa
End If
End Sub
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images